fix(forms): apply unicode flag to pattern attribute when supported (#20819)

Both Firefox and Chrome have applied unicode flag to the `pattern` content attribute of INPUT element.
See https://www.chromestatus.com/feature/4753420745441280

PR Close #20819
This commit is contained in:
Huáng Jùnliàng 2017-12-06 18:45:51 +08:00 committed by Igor Minar
parent 11a8bd8aca
commit 3c34b8b4f1
2 changed files with 10 additions and 1 deletions

View File

@ -379,6 +379,11 @@ export const PATTERN_VALIDATOR: any = {
* as the regex to validate Control value against. Follows pattern attribute * as the regex to validate Control value against. Follows pattern attribute
* semantics; i.e. regex must match entire Control value. * semantics; i.e. regex must match entire Control value.
* *
* Note: if a string type attribute value is used, the regex will be applied with the
* unicode flag on supported browsers. If a unicode-regex is passed, it might break on
* unsupported browser. In this case, the user should be responsible to handle the
* browser compatibility.
*
* @usageNotes * @usageNotes
* ### Example * ### Example
* *

View File

@ -306,7 +306,11 @@ export class Validators {
if (pattern.charAt(pattern.length - 1) !== '$') regexStr += '$'; if (pattern.charAt(pattern.length - 1) !== '$') regexStr += '$';
regex = new RegExp(regexStr); if (RegExp.prototype.hasOwnProperty('unicode')) {
regex = new RegExp(regexStr, 'u');
} else {
regex = new RegExp(regexStr);
}
} else { } else {
regexStr = pattern.toString(); regexStr = pattern.toString();
regex = pattern; regex = pattern;