Skip to content

Commit 659c67c

Browse files
author
Max Schaefer
committed
JavaScript: Produce friendlier message for empty-string replacements.
1 parent 5fb22ba commit 659c67c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

javascript/ql/src/RegExp/IdentityReplacement.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ predicate regExpMatchesString(RegExpTerm t, string s) {
6060
)
6161
}
6262

63-
from MethodCallExpr repl, string s
63+
from MethodCallExpr repl, string s, string friendly
6464
where repl.getMethodName() = "replace" and
6565
matchesString(repl.getArgument(0), s) and
66-
repl.getArgument(1).getStringValue() = s
67-
select repl.getArgument(0), "This replaces '" + s + "' with itself."
66+
repl.getArgument(1).getStringValue() = s and
67+
(if s = "" then friendly = "the empty string" else friendly = "'" + s + "'")
68+
select repl.getArgument(0), "This replaces " + friendly + " with itself."

0 commit comments

Comments
 (0)