diff --git a/ChangeLog b/ChangeLog index d54232a..c90b83c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2014-09-04 Jim Meyering + + fix "y" to work with NUL in the RHS + * sed/execute.c (do_list) [case 'y']: Handle NUL bytes + in the RHS of a y/LHS/RHS/ transliteration. + * testsuite/y-zero.good: New test-related files. + * testsuite/y-zero.inp: + * testsuite/y-zero.sed: + * testsuite/Makefile.am (SEDTESTS): Add y-zero here. + * testsuite/Makefile.tests: And here. + * NEWS (Bug fixes): Describe it. + The bug was reported by table@inventati.org, + with the execute.c change mostly by Paolo Bonzini. + 2014-07-24 Jose E. Marchesi * gnulib: Update. diff --git a/NEWS b/NEWS index e3c94c7..53c5132 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,20 @@ -Sed 4.2.2 +GNU sed NEWS -*- outline -*- + +* Noteworthy changes in release ?.? (????-??-??) [?] + +** Bug fixes + + The 'y' (transliterate) operator once again works with a NUL byte + on the RHS. E.g., sed 'y/b/\x00/' now works like tr b '\0'. GNU sed + has never before recognized \x00 in this context. However, sed-3.02 + and prior did accept a literal NUL byte in the RHS, which was possible + only when reading a script from a file. For example, this: + echo abc|sed -f <(printf 'y/b/\x00/\n')|cat -A + is what stopped working. [bug introduced some time after sed-3.02 and + prior to the first sed-4* test release] + + +* Noteworthy changes in release 4.2.2 (2012-12-22) [stable] * don't misbehave (truncate input) for lines of length 2^31 and longer diff --git a/sed/execute.c b/sed/execute.c index cb84192..2e13ee2 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -1567,7 +1567,8 @@ execute_program(vec, input) if (strncmp(line.active + idx, trans[2*i], mbclen) == 0) { bool move_remain_buffer = false; - int trans_len = strlen(trans[2*i+1]); + const char *tr = trans[2*i+1]; + size_t trans_len = *tr == '\0' ? 1 : strlen (tr); if (mbclen < trans_len) { diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index c670ee0..0501617 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -22,7 +22,7 @@ SEDTESTS += \ modulo numsub numsub2 numsub3 numsub4 numsub5 0range bkslashes \ head madding mac-mf empty xbxcx xbxcx3 recall recall2 xemacs \ fasts uniq manis khadafy linecnt eval distrib 8to7 y-bracket \ - y-newline allsub cv-vars classes middle bsd stdin flipcase \ + y-newline y-zero allsub cv-vars classes middle bsd stdin flipcase \ insens subwrite writeout readin insert utf8-1 utf8-2 utf8-3 utf8-4 \ badenc inplace-hold brackets amp-escape \ help version file quiet \ @@ -95,6 +95,7 @@ EXTRA_DIST = \ xbxcx3.good xbxcx3.inp xbxcx3.sed \ xemacs.good xemacs.inp xemacs.sed \ y-bracket.good y-bracket.sed y-bracket.inp \ + y-NUL.good y-NUL.sed y-NUL.inp \ y-newline.good y-newline.sed y-newline.inp # automake makes `check' depend on $(TESTS). Declare diff --git a/testsuite/Makefile.tests b/testsuite/Makefile.tests index 7aaf622..68fd077 100644 --- a/testsuite/Makefile.tests +++ b/testsuite/Makefile.tests @@ -21,7 +21,7 @@ SKIP = :>$@.skip; exit 77 enable sep inclib 8bit 8to7 newjis xabcx dollar noeol bkslashes \ numsub head madding mac-mf empty xbxcx xbxcx3 recall recall2 xemacs \ appquit fasts uniq manis linecnt khadafy allsub flipcase space modulo \ -y-bracket y-newline insert brackets amp-escape:: +y-bracket y-newline y-zero insert brackets amp-escape:: $(SEDENV) $(SED) -f $(srcdir)/$@.sed \ < $(srcdir)/$@.inp | $(TR) -d \\r > $@.out $(CMP) $(srcdir)/$@.good $@.out diff --git a/testsuite/y-zero.good b/testsuite/y-zero.good new file mode 100644 index 0000000..659b724 Binary files /dev/null and b/testsuite/y-zero.good differ diff --git a/testsuite/y-zero.inp b/testsuite/y-zero.inp new file mode 100644 index 0000000..8baef1b --- /dev/null +++ b/testsuite/y-zero.inp @@ -0,0 +1 @@ +abc diff --git a/testsuite/y-zero.sed b/testsuite/y-zero.sed new file mode 100644 index 0000000..6b0af7b --- /dev/null +++ b/testsuite/y-zero.sed @@ -0,0 +1 @@ +y/b/\x00/