Skip to content

Commit 71f5b71

Browse files
haoqunjiangLostlover
authored andcommitted
fix: avoid compression of unicode sequences by using regexps (vuejs#9595)
closes vuejs#9456
1 parent 06cd275 commit 71f5b71

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/compiler/parser/html-parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
import { makeMap, no } from 'shared/util'
1313
import { isNonPhrasingTag } from 'web/compiler/util'
14-
import { unicodeLetters } from 'core/util/lang'
14+
import { unicodeRegExp } from 'core/util/lang'
1515

1616
// Regular Expressions for parsing tags and attributes
1717
const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
1818
const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
19-
const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeLetters}]*`
19+
const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeRegExp.source}]*`
2020
const qnameCapture = `((?:${ncname}\\:)?${ncname})`
2121
const startTagOpen = new RegExp(`^<${qnameCapture}`)
2222
const startTagClose = /^\s*(\/?)>/

src/core/util/lang.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
66
* skipping \u10000-\uEFFFF due to it freezing up PhantomJS
77
*/
8-
export const unicodeLetters = 'a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD'
8+
export const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/
99

1010
/**
1111
* Check if a string starts with $ or _
@@ -30,7 +30,7 @@ export function def (obj: Object, key: string, val: any, enumerable?: boolean) {
3030
/**
3131
* Parse simple path.
3232
*/
33-
const bailRE = new RegExp(`[^${unicodeLetters}.$_\\d]`)
33+
const bailRE = new RegExp(`[^${unicodeRegExp.source}.$_\\d]`)
3434
export function parsePath (path: string): any {
3535
if (bailRE.test(path)) {
3636
return

src/core/util/options.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import config from '../config'
44
import { warn } from './debug'
55
import { set } from '../observer/index'
6-
import { unicodeLetters } from './lang'
6+
import { unicodeRegExp } from './lang'
77
import { nativeWatch, hasSymbol } from './env'
88

99
import {
@@ -277,7 +277,7 @@ function checkComponents (options: Object) {
277277
}
278278

279279
export function validateComponentName (name: string) {
280-
if (!new RegExp(`^[a-zA-Z][\\-\\.0-9_${unicodeLetters}]*$`).test(name)) {
280+
if (!new RegExp(`^[a-zA-Z][\\-\\.0-9_${unicodeRegExp.source}]*$`).test(name)) {
281281
warn(
282282
'Invalid component name: "' + name + '". Component names ' +
283283
'should conform to valid custom element name in html5 specification.'

0 commit comments

Comments
 (0)