2
0
mirror of https://codeberg.org/kiss-community/repo synced 2025-04-02 11:07:20 -06:00
repo/core/busybox/patches/awk-fix-literal-backslash.patch
2025-01-20 10:07:36 -06:00

20 lines
672 B
Diff

diff --git a/editors/awk.c b/editors/awk.c
index 64e752f4b..40f5ba7f7 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2636,8 +2636,13 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest /*,in
resbuf = qrealloc(resbuf, residx + replen + n, &resbufsize);
memcpy(resbuf + residx, sp + pmatch[j].rm_so - start_ofs, n);
residx += n;
- } else
+ } else {
+/* '\\' and '&' following a backslash keep its original meaning, any other
+ * occurrence of a '\\' should be treated as literal */
+ if (bslash && c != '\\' && c != '&')
+ resbuf[residx++] = '\\';
resbuf[residx++] = c;
+ }
bslash = 0;
}
}