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

Unified Diff: src/objects.cc

Issue 2137033002: [regexp] Fix regexp source escaping with preceding backslashes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix tests Created 4 years, 5 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/regress/regress-3229.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 2be1c1f3d861e786593327f343647153e1e21f19..caf991829d3909aae20c173bc034f13816ab1796 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -15876,7 +15876,13 @@ inline int CountRequiredEscapes(Handle<String> source) {
int escapes = 0;
Vector<const Char> src = source->GetCharVector<Char>();
for (int i = 0; i < src.length(); i++) {
- if (src[i] == '/' && (i == 0 || src[i - 1] != '\\')) escapes++;
+ if (src[i] == '\\') {
+ // Escape. Skip next character;
+ i++;
+ } else if (src[i] == '/') {
+ // Not escaped forward-slash needs escape.
+ escapes++;
+ }
}
return escapes;
}
@@ -15891,7 +15897,14 @@ inline Handle<StringType> WriteEscapedRegExpSource(Handle<String> source,
int s = 0;
int d = 0;
while (s < src.length()) {
- if (src[s] == '/' && (s == 0 || src[s - 1] != '\\')) dst[d++] = '\\';
+ if (src[s] == '\\') {
+ // Escape. Copy this and next character.
+ dst[d++] = src[s++];
+ if (s == src.length()) break;
+ } else if (src[s] == '/') {
+ // Not escaped forward-slash needs escape.
+ dst[d++] = '\\';
+ }
dst[d++] = src[s++];
}
DCHECK_EQ(result->length(), d);
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-3229.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698