Skip to content

Commit 6d8f54a

Browse files
authored
doc: fix manual description of regex escapes (#48239)
String interpolation happens before the regex is processed, so there is no guarantee that interpolated text will be properly escaped.
1 parent 7d2499d commit 6d8f54a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

doc/src/manual/strings.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,11 @@ true
10381038
```
10391039

10401040
Note the use of the `\Q...\E` escape sequence. All characters between the `\Q` and the `\E`
1041-
are interpreted as literal characters (after string interpolation). This escape sequence can
1042-
be useful when interpolating, possibly malicious, user input.
1041+
are interpreted as literal characters. This is convenient for matching characters that
1042+
would otherwise be regex metacharacters. However, caution is needed when using this feature
1043+
together with string interpolation, since the interpolated string might itself contain
1044+
the `\E` sequence, unexpectedly terminating literal matching. User inputs need to be sanitized
1045+
before inclusion in a regex.
10431046

10441047
## [Byte Array Literals](@id man-byte-array-literals)
10451048

0 commit comments

Comments
 (0)