Add string-replace-fewer-backslashes feature

This disables an extra round of escaping in the `string replace -r`
replacement string.

Currently, to add a backslash to an a or b (to "escape" it):

    string replace -ra '([ab])' '\\\\\\\$1' a

7 backslashes!

This removes one of the layers, so now 3 or 4 works (each one escaped
for the single-quotes, so pcre receives two, which it reads as one literal):

    string replace -ra '([ab])' '\\\\$1' a

This is backwards-incompatible as replacement strings will change
meaning, so we put it behind a feature flag.

The name is kinda crappy, though.

Fixes #5474.
This commit is contained in:
Fabian Homborg
2019-01-12 20:20:35 +01:00
parent a7a12c5c96
commit 864bb1f7a6
8 changed files with 17 additions and 2 deletions

View File

@@ -0,0 +1 @@
--features 'no-string-replace-fewer-backslashes' -C 'string replace -ra "\\\\" "\\\\\\\\" -- "a\b\c"'

View File

@@ -0,0 +1 @@
a\b\c

View File

@@ -0,0 +1 @@
--features 'string-replace-fewer-backslashes' -C 'string replace -ra "\\\\" "\\\\\\\\" -- "a\b\c"'

View File

@@ -0,0 +1 @@
a\\b\\c

View File

@@ -6,5 +6,6 @@ test_function
# Future Feature Flags
stderr-nocaret off 3.0 ^ no longer redirects stderr
qmark-noglob off 3.0 ? no longer globs
string-replace-fewer-backslashes off 3.1 string replace -r needs fewer backslashes in the replacement
1
2