Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Unified Diff: lib/compiler/implementation/lib/string_helper.dart

Issue 10411048: Fix issue 2756 where '$' has as special meaning in Javascript String.replace. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/corelib/string_replace_dollar_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/lib/string_helper.dart
===================================================================
--- lib/compiler/implementation/lib/string_helper.dart (revision 7782)
+++ lib/compiler/implementation/lib/string_helper.dart (working copy)
@@ -68,6 +68,14 @@
}
}
+stringReplaceJS(receiver, replacer, to) {
+ // The JavaScript String.replace method recognizes replacement
+ // patterns in the replacement string. Dart does not have that
+ // behavior.
+ to = JS('String', @"#.replace('$', '$$$$')", to);
+ return JS('String', @'#.replace(#, #)', receiver, replacer, to);
+}
+
stringReplaceAllUnchecked(receiver, from, to) {
if (from is String) {
if (from == "") {
@@ -89,12 +97,12 @@
var quoter = regExpMakeNative(quoteRegExp, global: true);
var quoted = JS('String', @'#.replace(#, "\\$&")', from, quoter);
RegExp replaceRegExp = new JSSyntaxRegExp(quoted, false, false);
- var replacer = regExpMakeNative(replaceRegExp, global: true);
- return JS('String', @'#.replace(#, #)', receiver, replacer, to);
+ var replacer = regExpMakeNative(replaceRegExp, global: true);
+ return stringReplaceJS(receiver, replacer, to);
}
} else if (from is JSSyntaxRegExp) {
var re = regExpMakeNative(from, global: true);
- return JS('String', @'#.replace(#, #)', receiver, re, to);
+ return stringReplaceJS(receiver, re, to);
} else {
checkNull(from);
// TODO(floitsch): implement generic String.replace (with patterns).
@@ -104,10 +112,10 @@
stringReplaceFirstUnchecked(receiver, from, to) {
if (from is String) {
- return JS('String', @'#.replace(#, #)', receiver, from, to);
+ return stringReplaceJS(receiver, from, to);
} else if (from is JSSyntaxRegExp) {
var re = regExpGetNative(from);
- return JS('String', @'#.replace(#, #)', receiver, re, to);
+ return stringReplaceJS(receiver, re, to);
} else {
checkNull(from);
// TODO(floitsch): implement generic String.replace (with patterns).
« no previous file with comments | « no previous file | tests/corelib/string_replace_dollar_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698