summaryrefslogtreecommitdiff
path: root/dist/Data-Dumper
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-05-13 09:59:11 +0000
committerNicholas Clark <nick@ccl4.org>2021-05-22 08:22:26 +0000
commit22d88af0e3e04dca72dcd494a6298431e57aeae0 (patch)
tree690c98e0c0733e492b53b2fd47df795b4b99c975 /dist/Data-Dumper
parent6514035f0b95a6a45e919660b27f0e89c2dfbe93 (diff)
downloadperl-22d88af0e3e04dca72dcd494a6298431e57aeae0.tar.gz
Document the scanning logic in Data::Dumper's dump_regexp.
Diffstat (limited to 'dist/Data-Dumper')
-rw-r--r--dist/Data-Dumper/Dumper.xs16
1 files changed, 16 insertions, 0 deletions
diff --git a/dist/Data-Dumper/Dumper.xs b/dist/Data-Dumper/Dumper.xs
index 9e545fc27c..fb86a21b70 100644
--- a/dist/Data-Dumper/Dumper.xs
+++ b/dist/Data-Dumper/Dumper.xs
@@ -656,6 +656,22 @@ dump_regexp(pTHX_ SV *retval, SV *val)
assert(sv_pattern);
+ /* The strategy here is from commit 7894fbab1e479c2c (in June 1999) with a
+ * bug fix in Feb 2012 (commit de5ef703c7d8db65).
+ * We need to ensure that / is escaped as \/
+ * To be efficient, we want to avoid copying byte-for-byte, so we scan the
+ * string looking for "things we need to escape", and each time we find
+ * something, we copy over the verbatim section, before writing out the
+ * escaped part. At the end, if there's some verbatim section left, we copy
+ * that over to finish.
+ * The complication (perl #58608) is that we must not convert \/ to \\/
+ * (as that would be a syntax error), so we need to walk the string looking
+ * for either
+ * \ and the character immediately after (together)
+ * a character
+ * and only for the latter, do we need to escape /
+ */
+
rval = SvPV(sv_pattern, rlen);
rend = rval+rlen;
slash = rval;