Re: [PATCH] vi: POSIX backslashes in expand_args
David Laight via busybox <[email protected]>
| Newsgroups | gmane.linux.busybox |
|---|---|
| Message-ID | <20260818090437.634da4f8@pumpkin> |
On Tue, 18 Aug 2026 08:54:11 +1000 Morgan via busybox <[email protected]> wrote: > vi: POSIX backslashes in expand_args POSIX won't say anything about the way vi should handle \ escapes. The best you can do is look at how other re-implementations of vi behave. David > > The previous behaviour treated every backslash as escaping a character, > rather than following POSIX, which only removes backslashes where they > are escaping a special character. > > And so only one backslash is lost when having a chain of backslashes > with a percent sign at the end. (plus any shell handling of backslashes > in unquoted arguments) > > Signed-off-by: Morgan Bartlett <[email protected]> > > diff --git a/editors/vi.c b/editors/vi.c > index ba607bcfd..d91a4a504 100644 > --- a/editors/vi.c > +++ b/editors/vi.c > @@ -2696,7 +2696,9 @@ static char *expand_args(char *args) > } else if (*s == '#') { > replace = alt_filename; > } else { > - if (*s == '\\' && s[1] != '\0') { > + /* According to POSIX, backslash-escapes are ignored > unless they > + * escape a special character. It gives an example > of \\% expanding to \% */ > + if (*s == '\\' && (s[1] == '%' || s[1] == '#')) { > char *t; > for (t = s; *t; t++) > *t = t[1]; > > > _______________________________________________ > busybox mailing list > [email protected] > https://lists.busybox.net/mailman/listinfo/busybox