aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2015-12-13 15:00:05 +1000
committerSteve Bennett <steveb@workware.net.au>2015-12-13 15:00:56 +1000
commit749313615f97b2498f39d2f2e5e293d2d6fc63d3 (patch)
tree7ccbca3d8fa53a34e26983a65c500c421a3c8595
parente56199a18844adff0b0d393a378ced02c9a4cd77 (diff)
downloadjimtcl-749313615f97b2498f39d2f2e5e293d2d6fc63d3.zip
jimtcl-749313615f97b2498f39d2f2e5e293d2d6fc63d3.tar.gz
jimtcl-749313615f97b2498f39d2f2e5e293d2d6fc63d3.tar.bz2
regsub: fix substitution with a trailing backslash
Should just replace with the bare backslash, not backslash '\0' Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-regexp.c5
-rw-r--r--tests/regexp.test5
2 files changed, 9 insertions, 1 deletions
diff --git a/jim-regexp.c b/jim-regexp.c
index 25ffd21..25e05a3 100644
--- a/jim-regexp.c
+++ b/jim-regexp.c
@@ -496,7 +496,10 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
continue;
}
else {
- Jim_AppendString(interp, resultObj, replace_str + j - 1, 2);
+ /* If the replacement is a trailing backslash, just replace with a backslash, otherwise
+ * with the literal backslash and the following character
+ */
+ Jim_AppendString(interp, resultObj, replace_str + j - 1, (j == replace_len) ? 1 : 2);
continue;
}
}
diff --git a/tests/regexp.test b/tests/regexp.test
index 7fa3ee0..a4e3f73 100644
--- a/tests/regexp.test
+++ b/tests/regexp.test
@@ -644,6 +644,11 @@ test regexp-21.14 {Literal newline in pattern} {
regexp -all -inline "\n(\[ \t\]+)" "\n\t\t# This is a test"
} "{\n\t\t} {\t\t}"
+test regexp-21.15 {Replace literal backslash} {
+ regsub -all <bs> {<bs>abc<bs>def} \\ value
+ set value
+} "\\abc\\def"
+
test regexp-22.1 {effect of caching} jim {
set filedata {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}