Last Comment Bug 1227906 - HTML `pattern` attribute should set `u` flag for regular expressions
: HTML `pattern` attribute should set `u` flag for regular expressions
Status: RESOLVED FIXED
: dev-doc-complete, site-compat
Product: Core
Classification: Components
Component: DOM (show other bugs)
: unspecified
: Unspecified Unspecified
: -- normal (vote)
: mozilla46
Assigned To: Tooru Fujisawa [:arai]
:
: Andrew Overholt [:overholt]
Mentors:
https://html.spec.whatwg.org/multipag...
Depends on: 1135377
Blocks:
  Show dependency treegraph
 
Reported: 2015-11-25 02:18 PST by Mathias Bynens
Modified: 2016-06-10 08:29 PDT (History)
6 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
fixed


Attachments
Use unicode flag in pattern attribute. (4.81 KB, patch)
2015-12-21 08:59 PST, Tooru Fujisawa [:arai]
jst: review+
Details | Diff | Splinter Review

Description User image Mathias Bynens 2015-11-25 02:18:32 PST
As soon as support for the `u` flag is completed, it should be enabled for the HTML `pattern` attribute as well.

Spec: https://html.spec.whatwg.org/multipage/forms.html#the-pattern-attribute

“If an input element has a pattern attribute specified, and the attribute's value, when compiled as a JavaScript regular expression with only the "u" flag specified, compiles successfully, then the resulting regular expression is the element's compiled pattern regular expression. If the element has no such attribute, or if the value doesn't compile successfully, then the element has no compiled pattern regular expression.”
Comment 1 User image Tooru Fujisawa [:arai] 2015-12-20 14:49:01 PST
bug 1135377 should be sufficient for implementing this :)

Then, I have one concern.
RegExp pattern with unicode flag disallows extended patterns (see bug 1135377 comment #53 for example), and I wonder if it results in some webcompat issue.
for example, <input pattern="\A[A-Z]{3}"> will accept "ABCD" and rejects "BCDE", but when unicode flag is set, pattern compilation will fail because of \A and pattern check won't work, and accepts all input.

might it be better showing some warning when the pattern compilation fails due to unicode flag?
Comment 2 User image Tooru Fujisawa [:arai] 2015-12-20 16:45:31 PST
about the extended patterns, following test doesn't work as expected because of escaped single-quote, that is not SyntaxCharacter and it's an invalid pattern.

https://dxr.mozilla.org/mozilla-central/rev/388bdc46ba51ee31da8b8abe977e0ca38d117434/dom/html/test/forms/test_pattern_attribute.html#174
>   // The same way, we want to escape the ' in the pattern.
>   element.pattern = "foo\\'bar";
>   element.value = "foo'bar";
>   checkValidPattern(element);
> 
>   // Check for 'i' flag disabled. Should be case sensitive.
>   element.value = "Foo";
>   checkInvalidPattern(element);

checkValidPattern there is passed, because no pattern match is performed, but next checkInvalidPattern fails with same reason.
(btw, I think that test is wrong. pattern should be "foo" for "Foo")

Similar case might exist on web.
Comment 3 User image Tooru Fujisawa [:arai] 2015-12-21 08:59:44 PST
Created attachment 8700667 [details] [diff] [review]
Use unicode flag in pattern attribute.

in case disallowing extended pattern doesn't matter (not sure if this is already discussed), here's a patch.
if it matters, please reject this and let's think how we could avoid/reduce web compat issue :)

Almost green on try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=15f613007121
Comment 4 User image Olli Pettay [:smaug] (review request backlog because of a work week) 2015-12-21 09:10:47 PST
Could you please file a spec bug about the possible backwards compatibility issue.
Comment 5 User image Tooru Fujisawa [:arai] 2015-12-21 09:54:05 PST
Thanks :)

reported here: https://github.com/whatwg/html/issues/439
Comment 6 User image Tooru Fujisawa [:arai] 2015-12-21 20:51:58 PST
I just noticed that SyntaxError is reported to Browser Console.
it should be better to report it to Web Console (maybe in separated bug)
Comment 7 User image Tooru Fujisawa [:arai] 2016-01-15 20:27:13 PST
https://hg.mozilla.org/integration/mozilla-inbound/rev/3a3edb6725a69dd0a4620b28408ae6717e8e724a
Bug 1227906 - Use unicode flag in pattern attribute. r=jst
Comment 8 User image Ryan VanderMeulen [:RyanVM] 2016-01-17 11:42:31 PST
https://hg.mozilla.org/mozilla-central/rev/3a3edb6725a6
Comment 9 User image Kohei Yoshino [:kohei] 2016-04-30 09:26:16 PDT
A Stack Overflow user has suffered from this change: http://stackoverflow.com/q/36953775/5693076

Posted the site compatibility doc: https://www.fxsitecompat.com/en-CA/docs/2016/input-pattern-now-sets-u-flag-for-regular-expressions/

MDN docs may require a double check.
Comment 10 User image Kohei Yoshino [:kohei] 2016-05-01 09:24:12 PDT
Another case posted on Firefox Input: https://input.mozilla.org/dashboard/response/5898357
Comment 11 User image Tooru Fujisawa [:arai] 2016-05-01 10:03:09 PDT
maybe we should describe more about the change in the warning message, with a link to MDN document?

Note You need to log in before you can comment on or make changes to this bug.