You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sed does not work as one might expect when the regex includes \n or otherwise spans multiple lines1, because it processes the input one line at a time, so if the expression matches multiple lines, sed never runs it over a large enough chunk of the input. This behavior is configurable — if one wishes to use multiline substitution sed can be made to keep more than one line at a time in memory, so it is not impossible to use multiline regexes with sed, but the code generator does not do so, instead it seems to only naively paste the regex and replacement into the s/// expression. I understand that it is not easy to generate the correct configuration for any possible regex, but the generator should not simply produce incorrect code either. If the correct command cannot be determined automatically, it could scan the expression for \n and emit an error instead of the command if found, and perhaps add a comment warning about the issue for any other expression, which might match a "hidden" newline through \s, \u000a, . or similar.
Reproduction steps
Create a substitution regex (any flavor) such as \[heading]\nvalue = true with any replacement, for example [heading]\nvalue = false
Open the sed code generator
Expected Outcome
A command which actually replaces matches of the given regular expression (I don't know sed well enough to craft one for the example expression I made)
Actual Outcome
A command which does not work, such as
sed -E 's/\[heading]\nvalue = true/[heading]\nvalue = false/gm;t'<<<"[heading]value = true"
Windows 10 Enterprise 22H2 19045.4651
sed command tested on Ubuntu 22.04 under WSL
Footnotes
I'm not actually very knowledgeable where sed is concerned, take everything I say about it here with a grain of salt and maybe somebody can correct me if I made a mistake. What I describe here stems simply from running into the same problem myself. ↩
The text was updated successfully, but these errors were encountered:
Bug Description
Sed does not work as one might expect when the regex includes
\n
or otherwise spans multiple lines1, because it processes the input one line at a time, so if the expression matches multiple lines, sed never runs it over a large enough chunk of the input. This behavior is configurable — if one wishes to use multiline substitution sed can be made to keep more than one line at a time in memory, so it is not impossible to use multiline regexes with sed, but the code generator does not do so, instead it seems to only naively paste the regex and replacement into the s/// expression. I understand that it is not easy to generate the correct configuration for any possible regex, but the generator should not simply produce incorrect code either. If the correct command cannot be determined automatically, it could scan the expression for\n
and emit an error instead of the command if found, and perhaps add a comment warning about the issue for any other expression, which might match a "hidden" newline through\s
,\u000a
,.
or similar.Reproduction steps
\[heading]\nvalue = true
with any replacement, for example[heading]\nvalue = false
Expected Outcome
A command which actually replaces matches of the given regular expression (I don't know sed well enough to craft one for the example expression I made)
Actual Outcome
A command which does not work, such as
To see that the given command does not work try it yourself or have a look at this online emulation: https://sed.js.org/?snippet=k7R59e
Browser
Firefox 130.0.1
OS
Windows 10 Enterprise 22H2 19045.4651
sed command tested on Ubuntu 22.04 under WSL
Footnotes
I'm not actually very knowledgeable where sed is concerned, take everything I say about it here with a grain of salt and maybe somebody can correct me if I made a mistake. What I describe here stems simply from running into the same problem myself. ↩
The text was updated successfully, but these errors were encountered: