The backtrackParenthesesOnceEnd function should store the start position
authorabecsi@webkit.org <abecsi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 May 2010 15:20:05 +0000 (15:20 +0000)
committerabecsi@webkit.org <abecsi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 May 2010 15:20:05 +0000 (15:20 +0000)
of the subpattern's non-greedy match at the place of the subpattern's
start index in the output array instead of the place of the
subpattern's end index.
Add layout test for checking of non-greedy matching of subpattern in
regular expressions.
https://bugs.webkit.org/show_bug.cgi?id=39289

Patch by Peter Varga <pvarga@inf.u-szeged.hu> on 2010-05-19
Reviewed by Darin Adler.

JavaScriptCore:

* yarr/RegexInterpreter.cpp:
(JSC::Yarr::Interpreter::backtrackParenthesesOnceEnd):

LayoutTests:

* fast/js/regexp-non-greedy-parentheses-expected.txt: Added.
* fast/js/regexp-non-greedy-parentheses.html: Added.
* fast/js/script-tests/regexp-non-greedy-parentheses.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@59766 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/yarr/RegexInterpreter.cpp
LayoutTests/ChangeLog
LayoutTests/fast/js/regexp-non-greedy-parentheses-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/regexp-non-greedy-parentheses.html [new file with mode: 0644]
LayoutTests/fast/js/script-tests/regexp-non-greedy-parentheses.js [new file with mode: 0644]

index b18d7d3..0cd7000 100644 (file)
@@ -1,3 +1,18 @@
+2010-05-19  Peter Varga  <pvarga@inf.u-szeged.hu>
+
+        Reviewed by Darin Adler.
+
+        The backtrackParenthesesOnceEnd function should store the start position
+        of the subpattern's non-greedy match at the place of the subpattern's
+        start index in the output array instead of the place of the
+        subpattern's end index.
+        Add layout test for checking of non-greedy matching of subpattern in
+        regular expressions.
+        https://bugs.webkit.org/show_bug.cgi?id=39289
+
+        * yarr/RegexInterpreter.cpp:
+        (JSC::Yarr::Interpreter::backtrackParenthesesOnceEnd):
+
 2010-05-18  Gavin Barraclough  <barraclough@apple.com>
 
         Reviewed by Geoff Garen.
index c2cb1c2..34ccc00 100644 (file)
@@ -674,7 +674,7 @@ public:
                 backTrack->inParentheses = 1;
                 if (term.capture()) {
                     unsigned subpatternId = term.atom.subpatternId;
-                    output[(subpatternId << 1) + 1] = input.getPos() + term.inputPosition;
+                    output[subpatternId << 1] = input.getPos() + term.inputPosition;
                 }
                 context->term -= term.atom.parenthesesWidth;
                 return true;
index 1fee29b..571a301 100644 (file)
@@ -1,3 +1,19 @@
+2010-05-19  Peter Varga  <pvarga@inf.u-szeged.hu>
+
+        Reviewed by Darin Adler.
+
+        The backtrackParenthesesOnceEnd function should store the start position
+        of the subpattern's non-greedy match at the place of the subpattern's
+        start index in the output array instead of the place of the
+        subpattern's end index.
+        Add layout test for checking of non-greedy matching of subpattern in
+        regular expressions.
+        https://bugs.webkit.org/show_bug.cgi?id=39289
+
+        * fast/js/regexp-non-greedy-parentheses-expected.txt: Added.
+        * fast/js/regexp-non-greedy-parentheses.html: Added.
+        * fast/js/script-tests/regexp-non-greedy-parentheses.js: Added.
+
 2010-05-19  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r59758.
diff --git a/LayoutTests/fast/js/regexp-non-greedy-parentheses-expected.txt b/LayoutTests/fast/js/regexp-non-greedy-parentheses-expected.txt
new file mode 100644 (file)
index 0000000..c9c0a83
--- /dev/null
@@ -0,0 +1,17 @@
+Test for regression against Wrong result in case of non-iterative matching of subpatterns in non-greedy cases in YARR Interpreter
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS "a".match(/(a)??/) is ["", undefined]
+PASS "b".match(/(a)??/) is ["", undefined]
+PASS "ab".match(/(a)??b/) is ["ab", "a"]
+PASS "aaab".match(/(a+)??b/) is ["aaab", "aaa"]
+PASS "abbc".match(/(a)??(b+)??c/) is ["abbc", "a", "bb"]
+PASS "ac".match(/(a)??(b)??c/) is ["ac", "a", undefined]
+PASS "abc".match(/(a(b)??)??c/) is ["abc", "ab", "b"]
+PASS "ac".match(/(a(b)??)??c/) is ["ac", "a", undefined]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/regexp-non-greedy-parentheses.html b/LayoutTests/fast/js/regexp-non-greedy-parentheses.html
new file mode 100644 (file)
index 0000000..0b6712c
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/regexp-non-greedy-parentheses.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/script-tests/regexp-non-greedy-parentheses.js b/LayoutTests/fast/js/script-tests/regexp-non-greedy-parentheses.js
new file mode 100644 (file)
index 0000000..c1b7a55
--- /dev/null
@@ -0,0 +1,14 @@
+description(
+'Test for regression against <a href="https://bugs.webkit.org/show_bug.cgi?id=39289">Wrong result in case of non-iterative matching of subpatterns in non-greedy cases in YARR Interpreter</a>'
+);
+
+shouldBe('"a".match(/(a)??/)', '["", undefined]');
+shouldBe('"b".match(/(a)??/)', '["", undefined]');
+shouldBe('"ab".match(/(a)??b/)', '["ab", "a"]');
+shouldBe('"aaab".match(/(a+)??b/)', '["aaab", "aaa"]');
+shouldBe('"abbc".match(/(a)??(b+)??c/)', '["abbc", "a", "bb"]');
+shouldBe('"ac".match(/(a)??(b)??c/)', '["ac", "a", undefined]');
+shouldBe('"abc".match(/(a(b)??)??c/)', '["abc", "ab", "b"]');
+shouldBe('"ac".match(/(a(b)??)??c/)', '["ac", "a", undefined]');
+
+var successfullyParsed = true;