Title: [229363] trunk
Revision
229363
Author
utatane....@gmail.com
Date
2018-03-07 09:44:06 -0800 (Wed, 07 Mar 2018)

Log Message

HTML `pattern` attribute should set `u` flag for regular expressions
https://bugs.webkit.org/show_bug.cgi?id=151598

Reviewed by Chris Dumez.

Source/_javascript_Core:

Add UnicodeMode for JSC::Yarr::RegularExpression.

* yarr/RegularExpression.cpp:
(JSC::Yarr::RegularExpression::Private::create):
(JSC::Yarr::RegularExpression::Private::Private):
(JSC::Yarr::RegularExpression::Private::compile):
(JSC::Yarr::RegularExpression::RegularExpression):
* yarr/RegularExpression.h:

Source/WebCore:

This patch attaches "u" flag to the RegExp compiled for HTML "pattern" attribute[1].

[1]: https://html.spec.whatwg.org/multipage/forms.html#the-pattern-attribute

* html/BaseTextInputType.cpp:
(WebCore::BaseTextInputType::patternMismatch const):

LayoutTests:

* fast/forms/ValidityState-patternMismatch-expected.txt:
* fast/forms/ValidityState-patternMismatch.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (229362 => 229363)


--- trunk/LayoutTests/ChangeLog	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/LayoutTests/ChangeLog	2018-03-07 17:44:06 UTC (rev 229363)
@@ -1,3 +1,13 @@
+2018-03-07  Yusuke Suzuki  <utatane....@gmail.com>
+
+        HTML `pattern` attribute should set `u` flag for regular expressions
+        https://bugs.webkit.org/show_bug.cgi?id=151598
+
+        Reviewed by Chris Dumez.
+
+        * fast/forms/ValidityState-patternMismatch-expected.txt:
+        * fast/forms/ValidityState-patternMismatch.html:
+
 2018-03-07  Frederic Wang  <fw...@igalia.com>
 
         Relayout frames after AsyncFrameScrolling or FrameFlattening option is changed

Modified: trunk/LayoutTests/fast/forms/ValidityState-patternMismatch-expected.txt (229362 => 229363)


--- trunk/LayoutTests/fast/forms/ValidityState-patternMismatch-expected.txt	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/LayoutTests/fast/forms/ValidityState-patternMismatch-expected.txt	2018-03-07 17:44:06 UTC (rev 229363)
@@ -28,6 +28,8 @@
 PASS patternMismatchFor("match-18") is false
 PASS patternMismatchFor("match-19") is false
 PASS patternMismatchFor("match-20") is false
+PASS patternMismatchFor("match-21") is false
+PASS patternMismatchFor("match-22") is false
 PASS patternMismatchFor("wrong-gray-or-grey") is true
 PASS patternMismatchFor("gray") is false
 PASS patternMismatchFor("grey") is false
@@ -53,6 +55,7 @@
 PASS patternMismatchFor("mismatch-19") is true
 PASS patternMismatchFor("mismatch-20") is true
 PASS patternMismatchFor("mismatch-21") is true
+PASS patternMismatchFor("mismatch-22") is true
 PASS patternMismatchFor("empty-pattern-match") is false
 PASS patternMismatchFor("empty-pattern-mismatch") is true
 PASS patternMismatchFor("invalid-01") is false
@@ -61,6 +64,8 @@
 PASS patternMismatchFor("invalid-04") is false
 PASS patternMismatchFor("invalid-05") is false
 PASS patternMismatchFor("invalid-06") is false
+PASS patternMismatchFor("invalid-07") is false
+PASS patternMismatchFor("invalid-08") is false
 PASS patternMismatchFor("disabled") is false
 PASS successfullyParsed is true
 

Modified: trunk/LayoutTests/fast/forms/ValidityState-patternMismatch.html (229362 => 229363)


--- trunk/LayoutTests/fast/forms/ValidityState-patternMismatch.html	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/LayoutTests/fast/forms/ValidityState-patternMismatch.html	2018-03-07 17:44:06 UTC (rev 229363)
@@ -32,6 +32,8 @@
 <input id="match-18" type="text" pattern="[0-9]|10|11|12" value="10" />
 <input id="match-19" type="text" pattern="10|11|12|[0-9]" value="12" />
 <input id="match-20" type="text" pattern="f(o|e)\1" value="foo" />
+<input id="match-21" type="text" pattern="a.b" value="a&#x1D306;b" />
+<input id="match-22" type="text" pattern="a..b" value="a&#x1D306;b" />
 <input id="empty-pattern-match" type="text" pattern="" value="" />
 <input id="wrong-gray-or-grey" type="text" pattern="gr[ae]y" value="Wrong!"
 /><input id="gray" type="text" pattern="gr[ae]y" value="gray"
@@ -57,7 +59,8 @@
 /><input id="mismatch-18" type="text" pattern="foo\\" value="food"
 /><input id="mismatch-19" type="text" pattern="^" value="wrong"
 /><input id="mismatch-20" type="text" pattern="$" value="wrong"
-/><input id="mismatch-21" type="text" pattern="f(o|e)\1" value="foe"/>
+/><input id="mismatch-21" type="text" pattern="f(o|e)\1" value="foe"
+/><input id="mismatch-22" type="text" pattern="a...b" value="a&#x1D306;b" />
 
 <input id="invalid-01" type="text" pattern=")foo(" value="foo"/>
 <input id="invalid-02" type="text" pattern=")foo(" value="foobar"/>
@@ -65,6 +68,8 @@
 <input id="invalid-04" type="text" pattern="foo\" value="foo\"/>
 <input id="invalid-05" type="text" pattern="[0-9" value="1"/>
 <input id="invalid-06" type="text" pattern="[0-9" value="a"/>
+<input id="invalid-07" type="text" pattern="foo\'bar" value="foo'bar"/>
+<input id="invalid-08" type="text" pattern="foo\'bar" value="foo"/>
 
 <input id="empty-pattern-mismatch" type="text" pattern="" value="Lorem Ipsum"
 /><input id="disabled" pattern="[0-9][A-Z]{3}" value="00AA" disabled /></div>
@@ -101,6 +106,8 @@
 shouldBeFalse('patternMismatchFor("match-18")');
 shouldBeFalse('patternMismatchFor("match-19")');
 shouldBeFalse('patternMismatchFor("match-20")');
+shouldBeFalse('patternMismatchFor("match-21")');
+shouldBeFalse('patternMismatchFor("match-22")');
 
 shouldBeTrue('patternMismatchFor("wrong-gray-or-grey")');
 shouldBeFalse('patternMismatchFor("gray")');
@@ -128,6 +135,7 @@
 shouldBeTrue('patternMismatchFor("mismatch-19")');
 shouldBeTrue('patternMismatchFor("mismatch-20")');
 shouldBeTrue('patternMismatchFor("mismatch-21")');
+shouldBeTrue('patternMismatchFor("mismatch-22")');
 
 shouldBeFalse('patternMismatchFor("empty-pattern-match")');
 shouldBeTrue('patternMismatchFor("empty-pattern-mismatch")');
@@ -138,6 +146,8 @@
 shouldBeFalse('patternMismatchFor("invalid-04")');
 shouldBeFalse('patternMismatchFor("invalid-05")');
 shouldBeFalse('patternMismatchFor("invalid-06")');
+shouldBeFalse('patternMismatchFor("invalid-07")');
+shouldBeFalse('patternMismatchFor("invalid-08")');
 
 shouldBeFalse('patternMismatchFor("disabled")');
 

Modified: trunk/Source/_javascript_Core/ChangeLog (229362 => 229363)


--- trunk/Source/_javascript_Core/ChangeLog	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-03-07 17:44:06 UTC (rev 229363)
@@ -1,5 +1,21 @@
 2018-03-07  Yusuke Suzuki  <utatane....@gmail.com>
 
+        HTML `pattern` attribute should set `u` flag for regular expressions
+        https://bugs.webkit.org/show_bug.cgi?id=151598
+
+        Reviewed by Chris Dumez.
+
+        Add UnicodeMode for JSC::Yarr::RegularExpression.
+
+        * yarr/RegularExpression.cpp:
+        (JSC::Yarr::RegularExpression::Private::create):
+        (JSC::Yarr::RegularExpression::Private::Private):
+        (JSC::Yarr::RegularExpression::Private::compile):
+        (JSC::Yarr::RegularExpression::RegularExpression):
+        * yarr/RegularExpression.h:
+
+2018-03-07  Yusuke Suzuki  <utatane....@gmail.com>
+
         [JSC] Add more JSType based fast path for jsDynamicCast
         https://bugs.webkit.org/show_bug.cgi?id=183403
 

Modified: trunk/Source/_javascript_Core/yarr/RegularExpression.cpp (229362 => 229363)


--- trunk/Source/_javascript_Core/yarr/RegularExpression.cpp	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/Source/_javascript_Core/yarr/RegularExpression.cpp	2018-03-07 17:44:06 UTC (rev 229363)
@@ -37,9 +37,9 @@
 
 class RegularExpression::Private : public RefCounted<RegularExpression::Private> {
 public:
-    static Ref<Private> create(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode)
+    static Ref<Private> create(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode, UnicodeMode unicodeMode)
     {
-        return adoptRef(*new Private(pattern, caseSensitivity, multilineMode));
+        return adoptRef(*new Private(pattern, caseSensitivity, multilineMode, unicodeMode));
     }
 
     int lastMatchLength { -1 };
@@ -48,12 +48,12 @@
     std::unique_ptr<JSC::Yarr::BytecodePattern> m_regExpByteCode;
 
 private:
-    Private(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode)
-        : m_regExpByteCode(compile(pattern, caseSensitivity, multilineMode))
+    Private(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode, UnicodeMode unicodeMode)
+        : m_regExpByteCode(compile(pattern, caseSensitivity, multilineMode, unicodeMode))
     {
     }
 
-    std::unique_ptr<JSC::Yarr::BytecodePattern> compile(const String& patternString, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode)
+    std::unique_ptr<JSC::Yarr::BytecodePattern> compile(const String& patternString, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode, UnicodeMode unicodeMode)
     {
         RegExpFlags flags = NoFlags;
 
@@ -63,6 +63,9 @@
         if (multilineMode == MultilineEnabled)
             flags = static_cast<RegExpFlags>(flags | FlagMultiline);
 
+        if (unicodeMode == UnicodeAwareMode)
+            flags = static_cast<RegExpFlags>(flags | FlagUnicode);
+
         JSC::Yarr::YarrPattern pattern(patternString, flags, m_constructionErrorCode);
         if (JSC::Yarr::hasError(m_constructionErrorCode)) {
             LOG_ERROR("RegularExpression: YARR compile failed with '%s'", JSC::Yarr::errorMessage(m_constructionErrorCode));
@@ -78,8 +81,8 @@
     JSC::Yarr::ErrorCode m_constructionErrorCode { Yarr::ErrorCode::NoError };
 };
 
-RegularExpression::RegularExpression(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode)
-    : d(Private::create(pattern, caseSensitivity, multilineMode))
+RegularExpression::RegularExpression(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode, UnicodeMode unicodeMode)
+    : d(Private::create(pattern, caseSensitivity, multilineMode, unicodeMode))
 {
 }
 

Modified: trunk/Source/_javascript_Core/yarr/RegularExpression.h (229362 => 229363)


--- trunk/Source/_javascript_Core/yarr/RegularExpression.h	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/Source/_javascript_Core/yarr/RegularExpression.h	2018-03-07 17:44:06 UTC (rev 229363)
@@ -31,11 +31,12 @@
 
 enum MultilineMode { MultilineDisabled, MultilineEnabled };
 enum TextCaseSensitivity { TextCaseSensitive, TextCaseInsensitive };
+enum UnicodeMode { UnicodeUnawareMode, UnicodeAwareMode };
 
 class JS_EXPORT_PRIVATE RegularExpression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit RegularExpression(const String&, TextCaseSensitivity = TextCaseSensitive, MultilineMode = MultilineDisabled);
+    explicit RegularExpression(const String&, TextCaseSensitivity = TextCaseSensitive, MultilineMode = MultilineDisabled, UnicodeMode = UnicodeUnawareMode);
     ~RegularExpression();
 
     RegularExpression(const RegularExpression&);

Modified: trunk/Source/WebCore/ChangeLog (229362 => 229363)


--- trunk/Source/WebCore/ChangeLog	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/Source/WebCore/ChangeLog	2018-03-07 17:44:06 UTC (rev 229363)
@@ -1,3 +1,17 @@
+2018-03-07  Yusuke Suzuki  <utatane....@gmail.com>
+
+        HTML `pattern` attribute should set `u` flag for regular expressions
+        https://bugs.webkit.org/show_bug.cgi?id=151598
+
+        Reviewed by Chris Dumez.
+
+        This patch attaches "u" flag to the RegExp compiled for HTML "pattern" attribute[1].
+
+        [1]: https://html.spec.whatwg.org/multipage/forms.html#the-pattern-attribute
+
+        * html/BaseTextInputType.cpp:
+        (WebCore::BaseTextInputType::patternMismatch const):
+
 2018-03-07  Frederic Wang  <fw...@igalia.com>
 
         Relayout frames after AsyncFrameScrolling or FrameFlattening option is changed

Modified: trunk/Source/WebCore/html/BaseTextInputType.cpp (229362 => 229363)


--- trunk/Source/WebCore/html/BaseTextInputType.cpp	2018-03-07 17:18:49 UTC (rev 229362)
+++ trunk/Source/WebCore/html/BaseTextInputType.cpp	2018-03-07 17:44:06 UTC (rev 229363)
@@ -39,13 +39,15 @@
 
 bool BaseTextInputType::patternMismatch(const String& value) const
 {
+    // FIXME: We should execute RegExp parser first to check validity instead of creating an actual RegularExpression.
+    // https://bugs.webkit.org/show_bug.cgi?id=183361
     const AtomicString& rawPattern = element().attributeWithoutSynchronization(patternAttr);
-    if (rawPattern.isNull() || value.isEmpty() || !JSC::Yarr::RegularExpression(rawPattern).isValid())
+    if (rawPattern.isNull() || value.isEmpty() || !JSC::Yarr::RegularExpression(rawPattern, JSC::Yarr::TextCaseSensitive, JSC::Yarr::MultilineDisabled, JSC::Yarr::UnicodeAwareMode).isValid())
         return false;
     String pattern = "^(?:" + rawPattern + ")$";
     int matchLength = 0;
     int valueLength = value.length();
-    int matchOffset = JSC::Yarr::RegularExpression(pattern).match(value, 0, &matchLength);
+    int matchOffset = JSC::Yarr::RegularExpression(pattern, JSC::Yarr::TextCaseSensitive, JSC::Yarr::MultilineDisabled, JSC::Yarr::UnicodeAwareMode).match(value, 0, &matchLength);
     return matchOffset || matchLength != valueLength;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to