The default bug view has changed. See this FAQ.

HTML `pattern` attribute should set `u` flag for regular expressions

RESOLVED FIXED in Firefox 46



a year ago
10 months ago


(Reporter: Mathias Bynens, Assigned: arai)


({dev-doc-complete, site-compat})

dev-doc-complete, site-compat

Firefox Tracking Flags

(firefox46 fixed)




(1 attachment)



a year ago
As soon as support for the `u` flag is completed, it should be enabled for the HTML `pattern` attribute as well.


“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.”


a year ago


a year ago
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?
Depends on: 1135377
No longer depends on: 887016
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.
>   // 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.
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:
Assignee: nobody → arai.unmht
Attachment #8700667 - Flags: review?(jst)
Could you please file a spec bug about the possible backwards compatibility issue.
Thanks :)

reported here:
I just noticed that SyntaxError is reported to Browser Console.
it should be better to report it to Web Console (maybe in separated bug)
See Also: → bug 1235159
Attachment #8700667 - Flags: review?(jst) → review+
Bug 1227906 - Use unicode flag in pattern attribute. r=jst

Comment 8

a year ago
Last Resolved: a year ago
status-firefox46: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla46

Comment 9

11 months ago
A Stack Overflow user has suffered from this change:

Posted the site compatibility doc:

MDN docs may require a double check.
Keywords: dev-doc-needed, site-compat

Comment 10

11 months ago
Another case posted on Firefox Input:
maybe we should describe more about the change in the warning message, with a link to MDN document?
I've made a small addition in:
and in:
Keywords: dev-doc-needed → dev-doc-complete
See Also: → bug 1279467
You need to log in before you can comment on or make changes to this bug.