Title: [221949] trunk
Revision
221949
Author
[email protected]
Date
2017-09-12 17:20:36 -0700 (Tue, 12 Sep 2017)

Log Message

String.prototype.replace() puts extra '<' in result when a named capture reference is used without named captures in the RegExp
https://bugs.webkit.org/show_bug.cgi?id=176814

Reviewed by Mark Lam.

Source/_javascript_Core:

The copy and advance indices where off by one and needed a little fine tuning.

* runtime/StringPrototype.cpp:
(JSC::substituteBackreferencesSlow):

LayoutTests:

New regression test case.

* js/regexp-named-capture-groups-expected.txt:
* js/script-tests/regexp-named-capture-groups.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221948 => 221949)


--- trunk/LayoutTests/ChangeLog	2017-09-13 00:13:01 UTC (rev 221948)
+++ trunk/LayoutTests/ChangeLog	2017-09-13 00:20:36 UTC (rev 221949)
@@ -1,3 +1,15 @@
+2017-09-12  Michael Saboff  <[email protected]>
+
+        String.prototype.replace() puts extra '<' in result when a named capture reference is used without named captures in the RegExp
+        https://bugs.webkit.org/show_bug.cgi?id=176814
+
+        Reviewed by Mark Lam.
+
+        New regression test case.
+
+        * js/regexp-named-capture-groups-expected.txt:
+        * js/script-tests/regexp-named-capture-groups.js:
+
 2017-09-12  Myles C. Maxfield  <[email protected]>
 
         ASSERTION FAILED: !m_valueOrException under FontFaceSet::completedLoading loading a Serious Eats page

Modified: trunk/LayoutTests/js/regexp-named-capture-groups-expected.txt (221948 => 221949)


--- trunk/LayoutTests/js/regexp-named-capture-groups-expected.txt	2017-09-13 00:13:01 UTC (rev 221948)
+++ trunk/LayoutTests/js/regexp-named-capture-groups-expected.txt	2017-09-13 00:20:36 UTC (rev 221949)
@@ -45,6 +45,7 @@
 PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$2-$<month>-$<year>") is "20-10-1930"
 PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$1-$<year>") is "20-10-1930"
 PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$3") is "20-10-1930"
+PASS "Replace just THIS in this string".replace(/THIS/, "$<THAT>") is "Replace just $<THAT> in this string"
 PASS "Give me a \'k\'!".match(/Give me a \'\k\'/)[0] is "Give me a \'k\'"
 PASS "Give me \'k2\'!".match(/Give me \'\k2\'/)[0] is "Give me \'k2\'"
 PASS "Give me a \'kat\'!".match(/Give me a \'\kat\'/)[0] is "Give me a \'kat\'"

Modified: trunk/LayoutTests/js/script-tests/regexp-named-capture-groups.js (221948 => 221949)


--- trunk/LayoutTests/js/script-tests/regexp-named-capture-groups.js	2017-09-13 00:13:01 UTC (rev 221948)
+++ trunk/LayoutTests/js/script-tests/regexp-named-capture-groups.js	2017-09-13 00:20:36 UTC (rev 221949)
@@ -77,6 +77,9 @@
 shouldBe('"10/20/1930".replace(/(?<month>\\d{2})\\\/(?<day>\\d{2})\\\/(?<year>\\d{4})/, "$<day>-$1-$<year>")', '"20-10-1930"');
 shouldBe('"10/20/1930".replace(/(?<month>\\d{2})\\\/(?<day>\\d{2})\\\/(?<year>\\d{4})/, "$<day>-$<month>-$3")', '"20-10-1930"');
 
+// Verify String.replace works correctly without named captures in the RegExp
+shouldBe('"Replace just THIS in this string".replace(/THIS/, "$<THAT>")', '"Replace just $<THAT> in this string"');
+
 // Verify that named back references for non-existing named group matches the k<groupName> for non-unicode patterns.
 shouldBe('"Give me a \\\'k\\\'!".match(/Give me a \\\'\\\k\\\'/)[0]', '"Give me a \\\'k\\\'"');
 shouldBe('"Give me \\\'k2\\\'!".match(/Give me \\\'\\\k2\\\'/)[0]', '"Give me \\\'k2\\\'"');

Modified: trunk/Source/_javascript_Core/ChangeLog (221948 => 221949)


--- trunk/Source/_javascript_Core/ChangeLog	2017-09-13 00:13:01 UTC (rev 221948)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-09-13 00:20:36 UTC (rev 221949)
@@ -1,3 +1,15 @@
+2017-09-12  Michael Saboff  <[email protected]>
+
+        String.prototype.replace() puts extra '<' in result when a named capture reference is used without named captures in the RegExp
+        https://bugs.webkit.org/show_bug.cgi?id=176814
+
+        Reviewed by Mark Lam.
+
+        The copy and advance indices where off by one and needed a little fine tuning.
+
+        * runtime/StringPrototype.cpp:
+        (JSC::substituteBackreferencesSlow):
+
 2017-09-11  Mark Lam  <[email protected]>
 
         More exception check book-keeping needed found by 32-bit JSC test failures.

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (221948 => 221949)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2017-09-13 00:13:01 UTC (rev 221948)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2017-09-13 00:20:36 UTC (rev 221949)
@@ -213,7 +213,8 @@
             // Named back reference
             if (!hasNamedCaptures) {
                 substitutedReplacement.append(replacement.substring(i, 2));
-                offset = i + 1;
+                offset = i + 2;
+                advance = 1;
                 continue;
             }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to