Assaf Gordon 0052daf1e5 sed: fix minor multibyte parsing bug
Previously sed would parse multibyte characters incorrectly in two scenarios:

1. Slash following an incomplete-yet-valid multibyte sequence (match_slash):
    $ LC_ALL=en_US.UTF-8 sed $'s/\316/X/'
    sed: -e expression #1, char 6: unterminated `s' command

2. Open/close brackets as part of a valid mutilbyte string inside a character
class (snarf_char_class). In the example below, '\203]' is a valid
multibyte character in SHIFT-JIS locale:

    $ LC_ALL=ja_JP.shiftjis sed $'/[\203]/]/p'
    sed: -e expression #1, char #5: Unmatched [ or [^

Both cases stem from mbcs.c:brlen() being non-intuitive:
It returned 1 for valid single-byte character, invalid multibyte-character,
and a for the last byte of a valid multibyte sequence - making it
non-trivial to use correctly.

This commit replaces brlen() with a simpler is_mb_char() function:
returns non-zero for multibyte sequences, zero for single/invalid sequences.

* sed/sed.h: (BRLEN, brlen): Remove delaration.
(IS_MB_CHAR,is_mb_char): Add macro and function declaration.
* sed/mbcs.c: (brlen): Remove function. (is_mb_char): New function.
* sed/compile.c: (snarf_char_class, match_slash): Use IS_MB_CHAR instead of
BRLEN; Adjust local variables accordingly.
* testsuite/mb-match-slash.sh: New test for scenario 1.
* testsuite/mb-charclass-non-utf8.sh: New test for scenario 2,
requires SHIFT-JIS locale.
* testsuite/Makefile.am: Add new tests
* testsuite/init.cfg: (require_ja_shiftjis_locale_): New function.
* NEWS: Mention bug fix.
2016-07-04 14:26:09 -04:00
2014-11-30 18:59:33 -08:00
2016-07-04 14:26:09 -04:00
2008-04-10 11:14:38 +02:00
2014-11-30 18:59:33 -08:00
2014-11-30 18:59:33 -08:00
2004-10-20 21:42:31 +00:00
2015-05-01 18:09:51 -07:00
2015-05-01 18:09:51 -07:00
2016-07-04 14:26:09 -04:00
2014-11-30 18:59:32 -08:00

This is the GNU implementation of sed, the Unix stream editor.

See the NEWS file for a brief summary and the ChangeLog for
more detailed descriptions of changes.

See the file INSTALL for generic compilation and installation
instructions.

See the file BUGS for instructions about reporting bugs.

The file README.boot gives instructions for making a "bootstrap"
version of sed on systems which lack any pre-existing and working
version of sed.
S
Description
SED (stream editor) - неинтерактивный текстовый редактор командной строки
https://www.gnu.org/software/sed/
Readme GPL-3.0
3 MiB
0 Stars 1 Watchers 0 Forks
Languages
Shell 43%
C 26.4%
Perl 16.5%
sed 7.3%
Makefile 5.2%
Other 1.6%