For a given pattern delimiter, d, POSIX specifies that the delimiter can be included in the pattern if it is backslash-escaped (i.e., \d). So in the case d == '\\', the ed command `s\\\' should be equivalent to `s/\\//p'. My current implementation treated this as `s///' instead.
The following commit fixes this (tests needed):
https://github.com/slewsys/ed/commit/cd2c4db24927df7b0009f5a9f1d4338d72cdfd11

GNU ed has an underlying bug: the command `s/pattern` is incorrectly flagged as an error due to a missing delimiter, whereas it has always been equivalent to `s/pattern//p'. Though not spelled out explicitly by POSIX, it is traditional behavior - and consistent with the line addressing expression `/pattern' (without terminating delimiter) which GNU ed does correctly handle.
-AM

On 4/23/23 10:01, Andrew L. Moore wrote:
On 4/22/23 02:59, v...@tuta.io wrote:
Maybe you haven't read it and you'll be interested:
https://austingroupbugs.net/view.php?id=1662

POSIX does not allow a backslash delimiter in ex, but does not disallow it for ed.  And indeed, The Open Group testsuite for ed does not complain if a backslash delimiter is supported.

I'm sharing this with GNU ed maintainer, Antonio Diaz, since a single backslash (\) is permitted as a (admittedly weird) pattern delimiter in GNU, macOS and *BSD ed as well, since they all share the same codebase.

Thank you for the heads up!
-AM



Reply via email to