sed: accept ** (documented GNU extension) in BRE mode
* sed/regexp.c (compile_regex_1): Clear RE_CONTEXT_INVALID_DUP for BRE, to accept ** as a GNU extension. In --posix mode, restore RE_CONTEXT_INVALID_DUP for BRE to enforce strict POSIX behavior. * NEWS: Mention this bug fix. * testsuite/bre-star-star.sh: New test. * testsuite/local.mk (T): Add it. Reported in https://debbugs.gnu.org/70476
This commit is contained in:
1 parent
47838d29e1
commit
7c375a2477
4 files changed
+58
-1
No files matched your search
@@ -4,6 +4,13 @@ GNU sed NEWS -*- outline -*-
|
||||
|
||||
** Bug fixes
|
||||
|
||||
sed no longer rejects the documented GNU extension 'a**' (equivalent
|
||||
to 'a*') in Basic Regular Expression (BRE) mode. Previously, this
|
||||
worked only with -E (ERE mode), even though grep has always accepted
|
||||
it in BRE mode.
|
||||
[bug present since "the beginning"]
|
||||
|
||||
|
||||
sed no longer rejects "\c[" in regular expressions
|
||||
[bug present since the beginning]
|
||||
|
||||
|
||||
+6
-1
@@ -52,6 +52,11 @@ compile_regex_1 (struct regex *new_regex, int needed_sub)
|
||||
syntax &= ~RE_DOT_NOT_NULL;
|
||||
syntax |= RE_NO_POSIX_BACKTRACKING;
|
||||
|
||||
/* As a GNU extension (for BRE), allow 'a**' to mean 'a*',
|
||||
just as grep does via RE_SYNTAX_GREP. */
|
||||
if (!(extended_regexp_flags & REG_EXTENDED))
|
||||
syntax &= ~RE_CONTEXT_INVALID_DUP;
|
||||
|
||||
switch (posixicity)
|
||||
{
|
||||
case POSIXLY_EXTENDED:
|
||||
@@ -63,7 +68,7 @@ compile_regex_1 (struct regex *new_regex, int needed_sub)
|
||||
case POSIXLY_BASIC:
|
||||
syntax |= RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS;
|
||||
if (!(extended_regexp_flags & REG_EXTENDED))
|
||||
syntax |= RE_LIMITED_OPS;
|
||||
syntax |= RE_LIMITED_OPS | RE_CONTEXT_INVALID_DUP;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
# Ensure that a** works in BRE mode (GNU extension)
|
||||
|
||||
# Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
||||
print_ver_ sed
|
||||
|
||||
unset POSIXLY_CORRECT
|
||||
export LC_ALL=C
|
||||
|
||||
# a** is a documented GNU extension meaning the same as a*
|
||||
# and must work in BRE mode, not just in ERE mode.
|
||||
printf '%s\n' 10 11 12 13 14 15 16 17 18 19 20 > in || framework_failure_
|
||||
printf '%s\n' 0 '' 2 3 4 5 6 7 8 9 20 > exp || framework_failure_
|
||||
|
||||
# BRE: was rejected before this fix
|
||||
sed 's/1**//' in > out-bre || fail=1
|
||||
compare_ exp out-bre || fail=1
|
||||
|
||||
# ERE: always worked
|
||||
sed -E 's/1**//' in > out-ere || fail=1
|
||||
compare_ exp out-ere || fail=1
|
||||
|
||||
# --posix BRE: must reject ** (not a POSIX feature)
|
||||
cat <<\EOF > exp-err || framework_failure_
|
||||
sed: -e expression #1, char 7: Invalid preceding regular expression
|
||||
EOF
|
||||
returns_ 1 sed --posix 's/1**//' in 2>err || fail=1
|
||||
compare_ exp-err err || fail=1
|
||||
|
||||
Exit $fail
|
||||
@@ -43,6 +43,7 @@ LOG_COMPILER = false
|
||||
|
||||
T = \
|
||||
testsuite/misc.pl \
|
||||
testsuite/bre-star-star.sh \
|
||||
testsuite/bug80573.sh \
|
||||
testsuite/bug32082.sh \
|
||||
testsuite/bug32271-1.sh \
|
||||
|
||||
Reference in new issue
Block a user