Reviewers: Kevin Millikin,

Message:
Fix for bug 667.

Description:
Fix bug in string replace with nonparticipating captures.

Please review this at http://codereview.chromium.org/1565004

Affected files:
  M src/runtime.cc
  M test/mjsunit/string-replace.js


Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 7d104fa3b4123eff2aedbed7af388e454f1458ac..abf9cdb139f837f1450eae4882d7dc29c0ac4df0 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -3357,11 +3357,16 @@ static RegExpImpl::IrregexpResult SearchRegExpMultiple(
                                                 match_start,
                                                 match_end));
         for (int i = 1; i <= capture_count; i++) {
-          Handle<String> substring =
-              Factory::NewSubString(subject,
-                                    register_vector[i * 2],
-                                    register_vector[i * 2 + 1]);
-          elements->set(i, *substring);
+          int start = register_vector[i * 2];
+          if (start >= 0) {
+                 int end = register_vector[i * 2 + 1];
+                 ASSERT(start <= end);
+ Handle<String> substring = Factory::NewSubString(subject, start, end);
+                             elements->set(i, *substring);
+          } else {
+                 ASSERT(register_vector[i * 2 + 1] < 0);
+                 elements->set(i, Heap::undefined_value());
+          }
         }
         elements->set(capture_count + 1, Smi::FromInt(match_start));
         elements->set(capture_count + 2, *subject);
Index: test/mjsunit/string-replace.js
diff --git a/test/mjsunit/string-replace.js b/test/mjsunit/string-replace.js
index ea6912724399bd37d99cd1d72ab1a33576f29616..a555c203cc847e4d98edb98c684b6dca91f22c53 100644
--- a/test/mjsunit/string-replace.js
+++ b/test/mjsunit/string-replace.js
@@ -178,13 +178,16 @@ longstring = longstring + longstring;
 longstring = longstring + longstring;
 // longstring.length == 5 << 11

-replaceTest(longstring + longstring,
+replaceTest(longstring + longstring,
             "<" + longstring + ">", /<(.*)>/g, "$1$1");
-
+
 replaceTest("string 42", "string x", /x/g, function() { return 42; });
-replaceTest("string 42", "string x", /x/, function() { return 42; });
+replaceTest("string 42", "string x", /x/, function() { return 42; });
 replaceTest("string 42", "string x", /[xy]/g, function() { return 42; });
 replaceTest("string 42", "string x", /[xy]/, function() { return 42; });
 replaceTest("string true", "string x", /x/g, function() { return true; });
 replaceTest("string null", "string x", /x/g, function() { return null; });
-replaceTest("string undefined", "string x", /x/g, function() { return undefined; }); +replaceTest("string undefined", "string x", /x/g, function() { return undefined; });
+
+replaceTest("aundefinedbundefinedcundefined",
+ "abc", /(.)|(.)/g, function(m, m1, m2, i, s) { return m1+m2; });


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

To unsubscribe from this group, send email to v8-dev+unsubscribegooglegroups.com or reply 
to this email with the words "REMOVE ME" as the subject.

Reply via email to