From owner-svn-src-head@freebsd.org Sun Jul 26 09:15:06 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 426103A20F5; Sun, 26 Jul 2020 09:15:06 +0000 (UTC) (envelope-from yuripv@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BDy2L13Gzz4K5n; Sun, 26 Jul 2020 09:15:06 +0000 (UTC) (envelope-from yuripv@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DE86CA835; Sun, 26 Jul 2020 09:15:05 +0000 (UTC) (envelope-from yuripv@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06Q9F5mj094458; Sun, 26 Jul 2020 09:15:05 GMT (envelope-from yuripv@FreeBSD.org) Received: (from yuripv@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06Q9F5YY094456; Sun, 26 Jul 2020 09:15:05 GMT (envelope-from yuripv@FreeBSD.org) Message-Id: <202007260915.06Q9F5YY094456@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: yuripv set sender to yuripv@FreeBSD.org using -f From: Yuri Pankov Date: Sun, 26 Jul 2020 09:15:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363543 - in head/usr.bin/sed: . tests X-SVN-Group: head X-SVN-Commit-Author: yuripv X-SVN-Commit-Paths: in head/usr.bin/sed: . tests X-SVN-Commit-Revision: 363543 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jul 2020 09:15:06 -0000 Author: yuripv Date: Sun Jul 26 09:15:05 2020 New Revision: 363543 URL: https://svnweb.freebsd.org/changeset/base/363543 Log: 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 Differential Revision: https://reviews.freebsd.org/D25640 Modified: head/usr.bin/sed/compile.c head/usr.bin/sed/tests/sed2_test.sh Modified: head/usr.bin/sed/compile.c ============================================================================== --- head/usr.bin/sed/compile.c Sun Jul 26 02:51:00 2020 (r363542) +++ head/usr.bin/sed/compile.c Sun Jul 26 09:15:05 2020 (r363543) @@ -437,11 +437,19 @@ compile_delimited(char *p, char *d, int is_tr) linenum, fname); while (*p) { if (*p == '[' && *p != c) { - if ((d = compile_ccl(&p, d)) == NULL) - errx(1, "%lu: %s: unbalanced brackets ([])", linenum, fname); - continue; + if (!is_tr) { + if ((d = compile_ccl(&p, d)) == NULL) { + errx(1, + "%lu: %s: unbalanced brackets ([])", + linenum, fname); + } + continue; + } } else if (*p == '\\' && p[1] == '[') { - *d++ = *p++; + if (is_tr) + p++; + else + *d++ = *p++; } else if (*p == '\\' && p[1] == c) { p++; } else if (*p == '\\' && Modified: head/usr.bin/sed/tests/sed2_test.sh ============================================================================== --- head/usr.bin/sed/tests/sed2_test.sh Sun Jul 26 02:51:00 2020 (r363542) +++ head/usr.bin/sed/tests/sed2_test.sh Sun Jul 26 09:15:05 2020 (r363543) @@ -134,6 +134,22 @@ commands_on_stdin_body() 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_add_test_case inplace_command_q @@ -142,4 +158,5 @@ atf_init_test_cases() atf_add_test_case escape_subst atf_add_test_case commands_on_stdin atf_add_test_case hex_subst + atf_add_test_case bracket_y }