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

Unified Diff: src/runtime.cc

Issue 1565004: Fix bug in string replace with nonparticipating captures. (Closed)
Patch Set: Untabified. Created 10 years, 9 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 | test/mjsunit/string-replace.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 7d104fa3b4123eff2aedbed7af388e454f1458ac..db0aabe7a431e77b13056d79a929360a3c0d5634 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);
« no previous file with comments | « no previous file | test/mjsunit/string-replace.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698