[PATCH] vi: POSIX backslashes in expand_args

Morgan via busybox <[email protected]>
Newsgroups gmane.linux.busybox
Message-ID <[email protected]>
vi: POSIX backslashes in expand_args

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];
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.