diff options
| author | Arnold D. Robbins <arnold@skeeve.com> | 2023-09-13 18:04:46 -0700 |
|---|---|---|
| committer | Arnold D. Robbins <arnold@skeeve.com> | 2023-09-13 18:04:46 -0700 |
| commit | a72e18316329e8e3a3b50f95f29e207b394d79f6 (patch) | |
| tree | 17dec995c74efbed698772429c6fcce20a5ab23f | |
| parent | c85749daba596ba2b827bcea239db74fc5321665 (diff) | |
| download | gawk-a72e18316329e8e3a3b50f95f29e207b394d79f6.tar.gz | |
Fix null matches around multibyte characters in sub/gsub.
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | builtin.c | 18 | ||||
| -rw-r--r-- | pc/ChangeLog | 4 | ||||
| -rw-r--r-- | pc/Makefile.tst | 12 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/Makefile.am | 8 | ||||
| -rw-r--r-- | test/Makefile.in | 14 | ||||
| -rw-r--r-- | test/Maketests | 6 | ||||
| -rw-r--r-- | test/gsubnulli18n.awk | 5 | ||||
| -rw-r--r-- | test/gsubnulli18n.ok | 1 |
10 files changed, 74 insertions, 8 deletions
@@ -1,3 +1,12 @@ +2023-09-13 Arnold D. Robbins <arnold@skeeve.com> + + Fix handling of zero length matching in multibyte locales + with sub/gsub. Thanks again to Ed Morton for the report. + + * builtin.c (do_sub): When the match is empty and we copy in + the subsequent character, check gawk_mb_cur_max to know whether + to copy one byte or multiple bytes. + 2023-09-01 Miguel Pineiro Jr <mpj@pineiro.cc> Fix the handling of zero-length matches in multibyte locales. @@ -2962,6 +2962,8 @@ do_match(int nargs) * * 7/2011: Reverted backslash handling to what it used to be. It was in * gawk for too long. Should have known better. + * + * 9/2023: Update for matches of null strings around multibyte characters. */ /* @@ -3264,8 +3266,20 @@ do_sub(int nargs, unsigned int flags) empty: /* catch the case of gsub(//, "blah", whatever), i.e. empty regexp */ if (matchstart == matchend && matchend < text + textlen) { - *bp++ = *matchend; - matchend++; + // copy in regular text + if (gawk_mb_cur_max == 1) { + *bp++ = *matchend; + matchend++; + } else { + mbstate_t mbs; + size_t i, j; + + memset(& mbs, 0, sizeof(mbs)); + j = mbrlen(matchend, (target->stptr + target->stlen) - matchend, & mbs); + // FIXME: Error checking on the value of `j' would be a good idea.... + for (i = 0; i < j; i++) + *bp++ = *matchend++; + } } textlen = text + textlen - matchend; text = matchend; diff --git a/pc/ChangeLog b/pc/ChangeLog index 2eea265..ba84284 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,7 @@ +2023-09-13 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.tst: Regenerated. + 2023-09-01 Arnold D. Robbins <arnold@skeeve.com> * Makefile.tst: Regenerated. diff --git a/pc/Makefile.tst b/pc/Makefile.tst index d1d7c85..afc7124 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -159,7 +159,8 @@ BASIC_TESTS = \ fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \ fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \ getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \ - getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \ + getnr2tm gsubasgn gsubnulli18n \ + gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \ gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \ intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \ math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \ @@ -310,7 +311,8 @@ NEED_LOCALE_C = \ clos1way gsubtst6 range2 NEED_LOCALE_EN = \ - backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \ + backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \ + gsubnulli18n ignrcas2 lc_num1 \ mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \ mtchi18n2 posix_compare \ printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \ @@ -1787,6 +1789,12 @@ gsubasgn: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +gsubnulli18n: + @echo $@ + @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=ENU_USA.1252; export GAWKLOCALE; \ + AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + gsubtest: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/ChangeLog b/test/ChangeLog index 7ed0832..28a0a0d 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2023-09-13 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): New test, gsubnulli18n. + * gsubnulli18n.awk, gsubnulli18n.ok: New files. + 2023-09-01 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): New test, mtchi18n2. diff --git a/test/Makefile.am b/test/Makefile.am index fe37d58..b20fa57 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -532,6 +532,8 @@ EXTRA_DIST = \ gsubasgn.ok \ gsubind.awk \ gsubind.ok \ + gsubnulli18n.awk \ + gsubnulli18n.ok \ gsubtest.awk \ gsubtest.ok \ gsubtst2.awk \ @@ -1483,7 +1485,8 @@ BASIC_TESTS = \ fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \ fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \ getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \ - getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \ + getnr2tm gsubasgn gsubnulli18n \ + gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \ gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \ intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \ math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \ @@ -1633,7 +1636,8 @@ NEED_LOCALE_C = \ clos1way gsubtst6 range2 NEED_LOCALE_EN = \ - backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \ + backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \ + gsubnulli18n ignrcas2 lc_num1 \ mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \ mtchi18n2 posix_compare \ printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \ diff --git a/test/Makefile.in b/test/Makefile.in index 7fe4e7a..5ed1b73 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -800,6 +800,8 @@ EXTRA_DIST = \ gsubasgn.ok \ gsubind.awk \ gsubind.ok \ + gsubnulli18n.awk \ + gsubnulli18n.ok \ gsubtest.awk \ gsubtest.ok \ gsubtst2.awk \ @@ -1751,7 +1753,8 @@ BASIC_TESTS = \ fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \ fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \ getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \ - getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \ + getnr2tm gsubasgn gsubnulli18n \ + gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \ gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \ intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \ math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \ @@ -1902,7 +1905,8 @@ NEED_LOCALE_C = \ clos1way gsubtst6 range2 NEED_LOCALE_EN = \ - backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \ + backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \ + gsubnulli18n ignrcas2 lc_num1 \ mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \ mtchi18n2 posix_compare \ printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \ @@ -3567,6 +3571,12 @@ gsubasgn: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +gsubnulli18n: + @echo $@ + @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; export GAWKLOCALE; \ + AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + gsubtest: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 8284e16..e7ad8c5 100644 --- a/test/Maketests +++ b/test/Maketests @@ -477,6 +477,12 @@ gsubasgn: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +gsubnulli18n: + @echo $@ + @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; export GAWKLOCALE; \ + AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + gsubtest: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/gsubnulli18n.awk b/test/gsubnulli18n.awk new file mode 100644 index 0000000..874586e --- /dev/null +++ b/test/gsubnulli18n.awk @@ -0,0 +1,5 @@ +BEGIN { + str = "אבג" + n = gsub(//, "x", str) + print n, str +} diff --git a/test/gsubnulli18n.ok b/test/gsubnulli18n.ok new file mode 100644 index 0000000..7099c3f --- /dev/null +++ b/test/gsubnulli18n.ok @@ -0,0 +1 @@ +4 xאxבxגx |
