Bug 253893 - sed "/^\s*$/d" complains about trailing backslash (\)
Summary: sed "/^\s*$/d" complains about trailing backslash (\)
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-27 14:41 UTC by freebsd
Modified: 2021-02-28 03:15 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description freebsd 2021-02-27 14:41:25 UTC
After an upgrade from 12.2 to 13.0-BETA3, python's virtualenvwrapper stopped working with a sed error. Source seems to be a pipeline akin to this:

> echo test/bin/activate | tr "\n" " " |  sed "s|/bin/activate |/|g" | tr "/" "\n" | sed "s/^\s*$/d"
sed: 1: "/^\s*$/d": RE error: trailing backslash (\)

If I mount the 12.2 boot environment and replace the sed calls in the above with /tmp/be<RANDOM>/usr/bin/sed, it works, as it has on 12.2:

> echo test/bin/activate | tr "\n" " " |  /tmp/be_mount.6Hlw/usr/bin/sed "s|/bin/activate |/|g" | tr "/" "\n" | /tmp/be_mount.6Hlw/usr/bin/sed "/^\s*$/d"
test
Comment 1 Yuri Pankov freebsd_committer 2021-02-27 17:27:23 UTC
Note that while the bug is actual, there is an error in your reproducer, `sed "s/^\s*$/d"` is wrong, there should not be an 's' command at the beginning.
Comment 2 Kyle Evans freebsd_committer 2021-02-27 17:32:43 UTC
(In reply to freebsd from comment #0)

Regardless of how 13 ends up, you should patch this to replace \s with [[:space:]]. This expression is not doing what the authors intended it to do on any other version of FreeBSD, and the new logic is only pointing that out.
Comment 3 David Schlachter 2021-02-27 17:38:31 UTC
A simpler test case is just:

printf "\n\n\n\n" | sed "/^\s*$/d"

Expected behaviour is that the empty lines will be filtered out.
Comment 4 David Schlachter 2021-02-27 18:12:43 UTC
I believe the error is raised in p_simp_re() in /usr/src/lib/libc/regex/regcomp.c.
Comment 5 Kyle Evans freebsd_committer 2021-02-27 18:14:13 UTC
(In reply to David Schlachter from comment #4)

Indeed, the error is quite intentional and to catch unexpected behavior like this.
Comment 6 freebsd 2021-02-28 02:34:23 UTC
(In reply to Kyle Evans from comment #5)
Do you mean this is expected behaviour now? Because from a user's point of view, this error message is rather unhelpful: what trailing backslash?

I can report that changing \s to [[:space:]] is working.
So how to proceed? Should I report this to virtualenvwrapper's upstream? Should the port maintainer add a patch?
Comment 7 Kyle Evans freebsd_committer 2021-02-28 03:15:24 UTC
(In reply to freebsd from comment #6)

Yes, the message leaves a lot to be desired, unfortunately; I've not yet been able to study the impact of changing the message since this reused a preexisting "escape error" condition.

Indeed, ideally this would both go upstream and to the local port maintainer as a POSIX compliance issue.