sed: treat '[' as ordinary character in 'y' command
'y' does not handle bracket expressions, treat '[' as ordinary character and do not apply bracket expression checks (GNU sed agrees). PR: 247931 Reviewed by: pfg, kevans Tested by: antoine (exp-run), Quentin L'Hours <lhoursquentin@gmail.com> Differential Revision: https://reviews.freebsd.org/D25640
This commit is contained in:
parent
18a48314ba
commit
14fdf16371
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363543
@ -437,10 +437,18 @@ compile_delimited(char *p, char *d, int is_tr)
|
|||||||
linenum, fname);
|
linenum, fname);
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p == '[' && *p != c) {
|
if (*p == '[' && *p != c) {
|
||||||
if ((d = compile_ccl(&p, d)) == NULL)
|
if (!is_tr) {
|
||||||
errx(1, "%lu: %s: unbalanced brackets ([])", linenum, fname);
|
if ((d = compile_ccl(&p, d)) == NULL) {
|
||||||
|
errx(1,
|
||||||
|
"%lu: %s: unbalanced brackets ([])",
|
||||||
|
linenum, fname);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
} else if (*p == '\\' && p[1] == '[') {
|
} else if (*p == '\\' && p[1] == '[') {
|
||||||
|
if (is_tr)
|
||||||
|
p++;
|
||||||
|
else
|
||||||
*d++ = *p++;
|
*d++ = *p++;
|
||||||
} else if (*p == '\\' && p[1] == c) {
|
} else if (*p == '\\' && p[1] == c) {
|
||||||
p++;
|
p++;
|
||||||
|
@ -134,6 +134,22 @@ commands_on_stdin_body()
|
|||||||
atf_check -o 'empty' sed -f - < insert_x
|
atf_check -o 'empty' sed -f - < insert_x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atf_test_case bracket_y
|
||||||
|
bracket_y_head()
|
||||||
|
{
|
||||||
|
atf_set "descr" "Verify '[' is ordinary character for 'y' command"
|
||||||
|
}
|
||||||
|
bracket_y_body()
|
||||||
|
{
|
||||||
|
atf_check -e empty -o ignore echo | sed 'y/[/x/'
|
||||||
|
atf_check -e empty -o ignore echo | sed 'y/[]/xy/'
|
||||||
|
atf_check -e empty -o ignore echo | sed 'y/[a]/xyz/'
|
||||||
|
atf_check -e empty -o "inline:zyx" echo '][a' | sed 'y/[a]/xyz/'
|
||||||
|
atf_check -e empty -o "inline:bracket\n" echo 'bra[ke]' | sed 'y/[]/ct/'
|
||||||
|
atf_check -e empty -o "inline:bracket\n" \
|
||||||
|
echo 'bra[ke]' | sed 'y[\[][ct['
|
||||||
|
}
|
||||||
|
|
||||||
atf_init_test_cases()
|
atf_init_test_cases()
|
||||||
{
|
{
|
||||||
atf_add_test_case inplace_command_q
|
atf_add_test_case inplace_command_q
|
||||||
@ -142,4 +158,5 @@ atf_init_test_cases()
|
|||||||
atf_add_test_case escape_subst
|
atf_add_test_case escape_subst
|
||||||
atf_add_test_case commands_on_stdin
|
atf_add_test_case commands_on_stdin
|
||||||
atf_add_test_case hex_subst
|
atf_add_test_case hex_subst
|
||||||
|
atf_add_test_case bracket_y
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user