253 Commits
Author SHA1 Message Date
Jim Meyering f04e0da045 tests: skip C-locale sub-tests when "C" is multibyte
* testsuite/mb-bad-delim.sh: Don't run the sub-test that uses an
incomplete multibyte byte as a single-byte delimiter in C locale.
* testsuite/mb-y-translate.sh: Don't run the two sub-tests that
expect a y/// length-mismatch error in C locale.
Android's bionic libc uses UTF-8 even in the C locale, so these
sub-tests would always fail.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00019.html
2026-04-21 08:30:31 -07:00
Jim Meyering 13604c8f68 tests: tolerate SELinux setfscreatecon warning on Android/Termux
* init.cfg (remove_selinux_warning_): New function.
* testsuite/in-place-hyphen.sh: Use it before comparing stderr.
* testsuite/in-place-suffix-backup.sh: Likewise.
* testsuite/panic-tests.sh: Likewise.
* testsuite/temp-file-cleanup.sh: Likewise.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00019.html
2026-04-21 08:11:48 -07:00
Jim Meyering 682d04b7d7 tests: skip read-error-stale-errno on Cygwin
* testsuite/read-error-stale-errno.sh: Skip when a FIFO with
O_NONBLOCK returns EOF instead of EAGAIN while a writer is still
attached.  Cygwin gets this wrong.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00011.html
2026-04-20 17:26:50 -07:00
Jim Meyering 6ec335494f sed: s///g now works for input lines longer than 2GB
* sed/regexp.c (match_regex): Change type of 'ret' from int
to regoff_t, to avoid truncation results larger than INT_MAX.
* testsuite/regex-max-int.sh: Update this "very expensive"
test to expect correct output (bbbbb) rather than exit-code-4 panic.
* NEWS (Bug fixes): Mention this.
The following is related but mostly incidental (--debug only).
I tested via --debug, (where it generate 20GB of output!), but couldn't
easily add a test case without adding a further option to suppress
debug printing of each escaped input line.
* sed/execute.c (do_subst): Don't cast regoff_t values to (int) for
debug printing via %d. Instead, cast to (ptrdiff_t) and print via %td.
2026-04-20 16:59:50 -07:00
Jim Meyering b99731ec2c tests: add a test for the just-fixed bug
* testsuite/read-error-stale-errno.sh: New file.
* testsuite/local.mk (T): Add it.
2026-04-19 20:17:47 -07:00
Jim Meyering a3f33e43ad tests: avoid panic-tests failure on multiple systems
* testsuite/panic-tests.sh: Test explicitly and skip if we can
still write to a directory that's been subject to "chmod a-w".
This struck on CentOS 7, Alma Linux, Alpine Linux and Cygwin.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00008.html
2026-04-18 22:21:48 -07:00
Jim Meyering feb70156f4 sed: a gnulib regex fix resolves long-standing backref bug
Surprisingly (comparing with the grep fix for this same bug), this
no-anchor case works properly both before and after the fix:
  $ echo ab | sed -E 's/^(.?)(.?).?\2\1/X/'
  Xb
That is because sed uses RE_NO_POSIX_BACKTRACKING, which avoids
grep's find-longest-match behavior (just fixed) that POSIX requires.

* gnulib: Update to latest for the regex bug fix.
* testsuite/backref-anchor.sh: New file. Test for this.
* testsuite/local.mk (T): Add the new file.
* NEWS (Bug fixes): Mention this.
* THANKS.in: Update.
Reported by Ed Morton in https://bugs.gnu.org/68725
2026-04-18 15:40:14 -07:00
Jim Meyering 53d12197e2 sed: --posix: fix escape handling after a named character class
With --posix, normalize_text tracks bracket-expression state to avoid
converting \X escapes inside bracket expressions.  It uses p[-1] and
p[-2] to detect the closing sequence of POSIX classes like [:alpha:].
However, normalize_text operates in-place with separate read (p)
and write (q) pointers, and when an earlier \n was collapsed from
two bytes to one, q falls behind p, so p[-1] and p[-2] read positions
already overwritten by q.

E.g., with '^A\n[[:alpha:]]\n*', the first \n shrinks, putting q one
byte behind p.  When processing the closing ']' in '[:alpha:]', p[-2]
reads ':' (written by q) rather than the original 'a', making the
"p[-2] != bracket_state" check fail.  Then, the second \n is never
converted to a newline.

* sed/compile.c (normalize_text): Use q[-1] and q[-2] for bracket
state tracking, not p[-1] and p[-2].
* NEWS: Mention this bug fix.
* testsuite/posix-bracket-esc.sh: New test.
* testsuite/local.mk (T): Add it.
Reported by Wolfgang Jeltsch in https://debbugs.gnu.org/77786
2026-04-11 16:19:38 -07:00
Bruno Haible 39c9ba576e tests: avoid test failure when running as root or in Cygwin
* testsuite/panic-tests.sh: When running as root or in Cygwin, skip the test.
2026-04-11 13:29:22 -07:00
Jim Meyering a6aebe155c sed: don't segfault for "sed -f<(echo ':label') --debug"
Using --debug after -f on the command line would deref uninitialized
memory usually evoking a segfault.
* sed/compile.c (next_cmd_entry): Zero-initialize the struct.
* sed/debug.c (debug_print_function): Print only when label_name
is non-NULL.
* testsuite/debug-label.sh: New test.
* testsuite/local.mk (T): Add it.
Reported in https://debbugs.gnu.org/70232
2026-04-11 13:17:39 -07:00
Jim Meyering 7c375a2477 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
2026-04-11 10:35:43 -07:00
Ash Roberts 47838d29e1 sed: do not allow removed 'L' command in compiler
* sed/compile.c: Remove cases for 'L' command.
* testsuite/compile-errors.sh: remove test for 'L' command in posix
mode. The 'L' command was removed in version 4.3, but was still allowed
by the compiler (resulting in an internal error when running a script
that uses it).  Reported in https://bugs.gnu.org/80704

Before, it would print this:
  $ echo | sed L1
  sed: INTERNAL ERROR: Bad cmd L
Now, it prints this:
  sed: -e expression #1, char 1: unknown command: 'L'
2026-04-10 18:57:01 -07:00
Weixie Cui 0e2491480a sed: avoid a one-time, one-byte leak
* sed/execute.c (line_reset): Also free buf->text when buf->alloc is zero.
* testsuite/bug80573.sh: New file.
* testsuite/local.mk (T): Add it to the list.
Demonstrate via this:
echo | valgrind --leak-check=full sed/sed -e x -e 's/.*/echo hi/e' 2>&1 | grep -A5 'definitely lost'
Reported in https://bugs.gnu.org/80573
2026-03-21 18:58:36 -07:00
Jim Meyering 03ec9a1080 maint: update copyright dates 2026-01-02 17:33:20 -08:00
Jim Meyering e137695202 sed: do not reject "\c[" in a regular expression
As a GNU extension, "\c[" in a regexp matches the ESC character
(i.e., control-[). Yet 's/\c[//' was rejected because "[" was treated
as the beginning of a bracket expression.
* sed/compile.c (match_slash): When matching "slash"es, treat \c as
an escape sequence, so that s/\c[// no longer fails because it
misinterprets [ as a bracket-group start.
* testsuite/misc.pl (bug79519_1,2,3,fail): Add tests.
* NEWS (Bug fixes): Mention it.
Reported by Michael Ludwig in https://bugs.gnu.org/79519.
2025-10-01 03:20:22 -07:00
Collin Funk 1cbc273262 sed: --posix now warns about nonportable backslashes in the 's' command
* sed/compile.c (match_slash): Convert regex parameter from int to bool
since all callers use true or false. Add s_command parameter and warn
about nonportable backslashes when true.
(compile_address, compile_program): Update calls to match_slash.
* testsuite/posix-backslash-warn.sh: New test.
* testsuite/local.mk (T): Add it.
* NEWS: Mention the change.
2025-08-24 16:08:17 -07:00
Jim Meyering b4d01a9c91 maint: ensure that new "make syntax-check"-run sc_codespell passes
* cfg.mk (codespell_ignore_words_list): Ignore false-positives.
(exclude_file_name_regexp--sc_codespell): Skip some file names.
* sed/debug.c: Fix typo(s).
* sed/mbcs.c: Likewise.
* sed/sed.c: Likewise.
* testsuite/badenc.sh: Likewise.
* testsuite/compile-errors.sh: Likewise.
* testsuite/distrib.inp: Likewise.
* testsuite/distrib.sh: Likewise.
* testsuite/execute-tests.sh: Likewise.
* testsuite/mb-bad-delim.sh: Likewise.
* testsuite/mb-charclass-non-utf8.sh: Likewise.
* testsuite/regex-max-int.sh: Likewise.
* testsuite/subst-options.sh: Likewise.
* testsuite/test-mbrtowc.c: Likewise.
* testsuite/utf8-ru.sh: Likewise.
2025-03-29 11:11:20 -07:00
Jim Meyering d3456f4482 maint: update all copyright dates via "make update-copyright" 2025-01-03 09:56:57 -08:00
Collin Funk 0c1fe22cca maint: import tests/init.sh from Gnulib during bootstrap
* bootstrap.conf (bootstrap_post_import_hook): Use gnulib-tool
--copy-file to import tests/init.sh.
* testsuite/init.sh: Remove file.
* .gitignore (/testsuite/init.sh): Add entry.
2024-07-04 14:30:46 -07:00
Jim Meyering 202d177800 build: update gnulib to latest; also update init.sh 2024-02-24 19:54:31 -08:00
Jim Meyering ad97abb865 maint: avoid syntax-check failure: use <>, not "" for system headers
* sed/sed.c: Spell as <getopt.h> and hoist it to be with other system
header includes. Also, use "", not <> for "selinux/selinux.h".
* testsuite/test-mbrtowc.c: Same, for <error.h>.
2024-02-23 08:50:18 -08:00
Jim Meyering 781bfba0bb build: update gnulib to latest; also update bootstrap and init.sh 2024-01-05 09:15:38 -08:00
Jim Meyering 2037812a6d maint: update copyright dates 2024-01-05 08:44:01 -08:00
Jim Meyering 26cf2ade2e sed: also print target file name upon rename failure
* sed/utils.c (ck_rename): When diagnosting rename failure,
also mention the target file name.
* testsuite/in-place-suffix-backup.sh: Adjust test expectations
to match.
Reported by Sebastian Carlos in https://bugs.gnu.org/63833
2023-06-10 18:15:34 -07:00
Paul Eggert fd9898dc4b maint: omit unnecessary Gnulib modules
* basicdefs.h: Do not include alloca.h.
* bootstrap.conf (gnulib_modules): Remove alloca, stdalign,
c-ctype, closeout, mbrlen, verify.
Add version-etc.
* lib/.gitignore, m4/.gitignore: Omit now-unused files.
* po/POTFILES.in: Remove closeout.c.
* testsuite/test-mbrtowc.c: Do not include closeout.h.
(main): Close stdout by hand, to avoid a dependency on closeout.
2023-01-30 09:58:54 -08:00
Paul Eggert 8c802c5078 maint: quote 'like this' not `like this' 2023-01-30 09:58:54 -08:00
Jim Meyering fa9e4e4fc0 tests: reflect recent diagnostic change
v4.9-14-g3d75b4a changed the diagnostic, but did not update
the occurrences of the diagnostic in expected test outputs.
* testsuite/compile-errors.sh: Accommodate changed diagnostic.
* testsuite/mb-y-translate.sh: Likewise.
* testsuite/normalize-text.sh: Likewise.
Reported by Bruno Haible in https://bugs.gnu.org/61159
2023-01-29 17:36:34 -08:00
Jim Meyering d81710cc8d maint: update copyright dates 2023-01-01 17:19:34 -08:00
Paul Eggert 602c0cb92c maint: add test cases for integer overflow
* testsuite/execute-tests.sh: Add some tests with
enormous integers.
2022-12-19 13:47:19 -08:00
Paul Eggert 8f600f2df2 sed: fix symlink bufsize readlink check
Problem reported by Hauke Mehrtens.
* sed/utils.c (follow_symlink): Fix typo when checking size of
second and later symlink, when that symlink is so large that it
does not fit into the buffer.  Although the bug is not a buffer
overflow, it does cause sed to mishandle the symlink.
* testsuite/follow-symlinks.sh: Test for the bug.
2022-12-17 20:57:23 -08:00
Jim Meyering 3fe543665c build: update gnulib to latest, and testsuite/init.sh 2022-11-06 11:38:14 -08:00
Jim Meyering 8efd09941e tests: do not rely on unportable "grep -q"
* testsuite/inplace-selinux.sh: Avoid unportable "grep -q".
Instead, just redirect to /dev/null.
2022-11-06 10:57:11 -08:00
Jim Meyering 59c6f17a71 test: add a test case and mention the change in NEWS
* testsuite/misc.pl: Add a test to exercise the preceding change.
* NEWS (Changes in behavior): Mention it.
2022-10-23 23:10:26 -07:00
Marvin Schmidt bd37192878 tests: remove stray export-ending semicolon in test setup
* testsuite/local.mk (TESTS_ENVIRONMENT): Remove the erroneous ";"
that effectively elided all following var=val pairs from the test
environment. Report and patch from http://bugs.gnu.org/57831
Bug introduced via v4.2.2-100-gb250bd4.
2022-09-15 12:51:36 -07:00
Paul Eggert 40dba28572 sed: fix infloop with symlink cycles
* bootstrap.conf (gnulib_modules):
Add eloop-threshold, idx, minmax, readlink.
* configure.ac: Do not check for lstat; no longer needed.
(ENABLE_FOLLOW_SYMLINKS): Remove; all uses removed.
(TEST_SYMLINKS): Depend only on readlink.
* sed/utils.c: Include eloop-threshold.h, idx.h, minmax.h.
(SSIZE_IDX_MAX): New macro.
(follow_symlink): Rewrite to not loop when given a symlink cycle.
Do not use lstat, since readlink suffices.  Use just one memory
buffer, not two; this simplifies memory management.
* testsuite/follow-symlinks.sh: Adjust diagnostics to
to match revised behavior.  Test for symlink loops.
2022-07-03 18:17:41 -05:00
Paul Eggert de2194891a Remove unused BOOST.tests, PCRE.tests, SPENCER.tests 2022-07-02 17:06:39 -05:00
Paul Eggert e69bb8436f Remove unused files testcases.h, ptestcases.h 2022-07-02 17:06:39 -05:00
Chris Marusich b8f98f7dc3 tests: export CONFIG_HEADER to test scripts
Before this change, the testsuite/inplace-selinux test fails in some
cases when SELinux is available.  The reason it fails is because the
require_selinux_ function in init.cfg expects the CONFIG_HEADER
environment variable to be defined, but in fact it is not defined.
Even though we do invoke AM_CONFIG_HEADER in configure.ac, and even
though the CONFIG_HEADER variable does get set in the resulting
Makefile, nothing actually exports the CONFIG_HEADER variable, so the
test is doomed to fail whenever it is not skipped.  Fix this by
exporting the variable.

* testsuite/local.mk (TESTS_ENVIRONMENT): Add CONFIG_HEADER to the
list of variables to export to the environment of the test scripts.

Reported by Vineet Jain <vkjain@gmail.com> in
https://bugs.gnu.org/36150 .  The fix was suggested by Timothy Sample
<samplet@ngyro.com> in the same bug report.
2022-02-13 11:08:03 -08:00
Jim Meyering 0c8d88bc61 maint: make update-copyright 2022-01-01 15:00:18 -08:00
Jim Meyering 13c54aac5b build: update gnulib to latest; also bootstrap and init.sh 2022-01-01 14:58:10 -08:00
Assaf Gordon 07c9c74c6b sed: allow '0rFILE' (insert FILE before the first line)
The 'r' command can be used with address zero, effectively prepending
a file to the beginning of the input file, e.g.:
    sed '0rA.TXT' B.TXT > C.TXT
is equivalent to:
    cat A.TXT B.TXT > C.TXT

With "sed -i", this allows safe in-place prepending of files.
A typical example would be adding a license header to multiple source
files:
    sed -i '0rLICENSE' *.c *.h
    find -iname '*.cpp' | xargs sed -i '0rLICENSE'

A current cumbersome alternative is:
    sed -i -e 'x;${p;x};1rA.TXT' -e '1d'  B.TXT

* NEWS: Mention new feature.
* sed/sed.h (struct readcmd): New struct. (struct sed_cmd): Use new
struct instead of a char* for the filename.
* sed/compile.c (compile_program): Expand conditional detecting invalid
usage of "0" address to allow "0r"; Adjust '0r' to '1r' with prepending
(instead of appending).
* sed/execute.c (execute_program): 'r' command: support prepending.
* sed/debug.c (debug_print_function): Use the new 'struct readcmd'.
* testsuite/cmd-0r.sh: New test.
* testsuite/local.mk (TESTS): Add new test.
* doc/sed.texi (Zero Address): New section. (Adding a header to multiple
files): New example section.
2021-08-16 12:34:20 -06:00
Assaf Gordon 71de42fd34 maint: update all copyright year number ranges
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* bootstrap.conf (gnulib_modules): Remove getopt module, depracated in
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=0abc38bd2a1398f0
* po/POTFILES.in: Remove getopt.c
* sed/utils.h (panic): Rename _GL_ATTRIBUTE_FORMAT_PRINTF to
_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD following gnulib's change:
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=387d654cabd7bc15
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
2021-01-05 17:02:10 -07:00
Jim Meyering 8f2f1b7182 tests: remove valgrind-added diagnostics from stderr
* testsuite/bug32271-2.sh: Filter out lines starting with "==".
This avoids unwarranted failures on e.g., windows systems that
would emit this to stderr:
+==16281== error calling PR_SET_PTRACER, vgdb might block
* testsuite/newline-dfa-bug.sh: Likewise.
Reported by Vagelis Prokopiou on Windows subsystem for Linux
(Debian 10) in https://lists.gnu.org/r/sed-devel/2020-01/msg00018.html
and by Bruno Haible for mingw in
https://lists.gnu.org/r/sed-devel/2020-01/msg00005.html
2020-01-11 20:49:51 -08:00
Jim Meyering 5766a98647 tests: avoid hpux11 test failure
* testsuite/title-case.sh: Correct printf usage not to trigger
unspecified behavior for '\(\)'. Instead, just use sed with its -r
option so those parentheses don't need any backslash at all.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2020-01/msg00008.html
2020-01-11 16:18:50 -08:00
Jim Meyering 598c3a0dd9 tests: handle missing perl
Before this change, the two perl-requiring tests would fail
on systems without perl. Now, they are skipped, as intended.
* bootstrap.conf (gnulib_modules): Add perl.
* testsuite/no-perl: New file. From coreutils.
* testsuite/local.mk (EXTRA_DIST): Add it.
(TESTSUITE_PERL): Include testsuite/ prefix.
2020-01-09 22:56:39 -08:00
Jim Meyering 623f5cd2f9 maint: update all copyright year number ranges
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
2020-01-01 11:38:46 -08:00
Assaf Gordon a9cb52bcf3 tests: inplace-selinux.sh: skip if SELinux is not supported
Avoid false-positive failure on system with SELinux enabled when SED
is built without SELinux suppport.

Reported by Jeffrey Walton <noloader@gmail.com> in
https://bugs.gnu.org/35997 .

* testsuite/inplace-selinux.sh: Call 'sed --version' to check if sed
was built with SELinux support before continuing with the test.
2019-06-02 01:14:00 -06:00
Assaf Gordon 07df2c2e61 maint: update copyright dates for 2019
* all files: Run "make update-copyright".
2019-01-01 14:46:27 -07:00
Jim Meyering 799ce52011 sed: fix \b DFA-bug in C locale
Under some conditions, \b would mistakenly fail to match. E.g.,
this would mistakenly print "123-x" instead of "123":
  echo 123-x|LC_ALL=C sed 's/.\bx//'
* NEWS (Bug fixes): Mention it
* gnulib: Update to latest, for DFA regression fix.
* testsuite/word-delim.sh: New file, to test for the dfa.c regression.
* testsuite/local.mk (T): Add it.
Reported by Jan Palus in
https://lists.gnu.org/r/sed-devel/2018-12/msg00022.html
2018-12-20 21:23:11 -08:00
Assaf Gordon 5155e56775 tests: fix obinary test error due to 'wc' spaces
On BSD systems "wc -c" prefixes the count with spaces,
leading to test error.
Discussed in https://lists.gnu.org/r/sed-devel/2018-12/msg00014.html .

* testsuite/obinary.sh: Remove leading spaces from 'wc -c' output.
2018-12-13 15:59:44 -07:00