View | Details | Raw Unified | Return to bug 247931
Collapse All | Expand All

(-)b/usr.bin/sed/compile.c (-5 / +13 lines)
Lines 437-447 compile_delimited(char *p, char *d, int is_tr) Link Here
437
				linenum, fname);
437
				linenum, fname);
438
	while (*p) {
438
	while (*p) {
439
		if (*p == '[' && *p != c) {
439
		if (*p == '[' && *p != c) {
440
			if ((d = compile_ccl(&p, d)) == NULL)
440
			if (!is_tr) {
441
				errx(1, "%lu: %s: unbalanced brackets ([])", linenum, fname);
441
				if ((d = compile_ccl(&p, d)) == NULL) {
442
			continue;
442
					errx(1,
443
					    "%lu: %s: unbalanced brackets ([])",
444
					    linenum, fname);
445
				}
446
				continue;
447
			}
443
		} else if (*p == '\\' && p[1] == '[') {
448
		} else if (*p == '\\' && p[1] == '[') {
444
			*d++ = *p++;
449
			if (is_tr)
450
				p++;
451
			else
452
				*d++ = *p++;
445
		} else if (*p == '\\' && p[1] == c) {
453
		} else if (*p == '\\' && p[1] == c) {
446
			p++;
454
			p++;
447
		} else if (*p == '\\' &&
455
		} else if (*p == '\\' &&
Lines 465-471 compile_delimited(char *p, char *d, int is_tr) Link Here
465
				p += hexlen + 2;
473
				p += hexlen + 2;
466
				continue;
474
				continue;
467
			}
475
			}
468
		} else if (*p == '\\' && p[1] == '\\') {
476
		} else if (*p == '\\') {
469
			if (is_tr)
477
			if (is_tr)
470
				p++;
478
				p++;
471
			else
479
			else
(-)b/usr.bin/sed/tests/sed2_test.sh (+17 lines)
Lines 134-139 commands_on_stdin_body() Link Here
134
	atf_check -o 'empty' sed -f - < insert_x
134
	atf_check -o 'empty' sed -f - < insert_x
135
}
135
}
136
136
137
atf_test_case bracket_y
138
bracket_y_head()
139
{
140
	atf_set "descr" "Verify '[' is ordinary character for 'y' command"
141
}
142
bracket_y_body()
143
{
144
	atf_check -e empty -o ignore echo | sed 'y/[/x/'
145
	atf_check -e empty -o ignore echo | sed 'y/[]/xy/'
146
	atf_check -e empty -o ignore echo | sed 'y/[a]/xyz/'
147
	atf_check -e empty -o "inline:zyx" echo '][a' | sed 'y/[a]/xyz/'
148
	atf_check -e empty -o "inline:bracket\n" echo 'bra[ke]' | sed 'y/[]/ct/'
149
	atf_check -e empty -o "inline:bracket\n" \
150
	    echo 'bra[ke]' | sed 'y[\[][ct['
151
}
152
137
atf_init_test_cases()
153
atf_init_test_cases()
138
{
154
{
139
	atf_add_test_case inplace_command_q
155
	atf_add_test_case inplace_command_q
Lines 142-145 atf_init_test_cases() Link Here
142
	atf_add_test_case escape_subst
158
	atf_add_test_case escape_subst
143
	atf_add_test_case commands_on_stdin
159
	atf_add_test_case commands_on_stdin
144
	atf_add_test_case hex_subst
160
	atf_add_test_case hex_subst
161
	atf_add_test_case bracket_y
145
}
162
}

Return to bug 247931