Index: sdk/lib/_internal/js_runtime/lib/string_helper.dart |
diff --git a/sdk/lib/_internal/js_runtime/lib/string_helper.dart b/sdk/lib/_internal/js_runtime/lib/string_helper.dart |
index 904c5e913deed71e3d7749a82c452aa25c3b41ee..9ce91f8a179d7505935707a47ea45e8fef2c2f6d 100644 |
--- a/sdk/lib/_internal/js_runtime/lib/string_helper.dart |
+++ b/sdk/lib/_internal/js_runtime/lib/string_helper.dart |
@@ -130,6 +130,8 @@ stringReplaceFirstRE(receiver, regexp, replacement, startIndex) { |
return stringReplaceRangeUnchecked(receiver, start, end, replacement); |
} |
+const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; |
+ |
stringReplaceAllUnchecked(receiver, pattern, replacement) { |
checkString(replacement); |
if (pattern is String) { |
@@ -147,10 +149,8 @@ stringReplaceAllUnchecked(receiver, pattern, replacement) { |
return result.toString(); |
} |
} else { |
- // Convert string [pattern] into a RegExp [replacer], escaping all |
- // metacharacters. |
- var quoted = JS('String', |
- r'#.replace(/[[\]{}()*+?.\\^$|]/g, "\\$&")', pattern); |
+ var quoter = JS('', "new RegExp(#, 'g')", ESCAPE_REGEXP); |
+ var quoted = JS('String', r'#.replace(#, "\\$&")', pattern, quoter); |
var replacer = JS('', "new RegExp(#, 'g')", quoted); |
return stringReplaceJS(receiver, replacer, replacement); |
} |