Skip to content

Commit

Permalink
fix: avoid compression of unicode sequences by using regexps (vuejs#9595
Browse files Browse the repository at this point in the history
)

closes vuejs#9456
  • Loading branch information
sodatea authored and kiku-jw committed Jun 18, 2019
1 parent 6b487b3 commit 67ce99a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/compiler/parser/html-parser.js
Expand Up @@ -11,12 +11,12 @@

import { makeMap, no } from 'shared/util'
import { isNonPhrasingTag } from 'web/compiler/util'
import { unicodeLetters } from 'core/util/lang'
import { unicodeRegExp } from 'core/util/lang'

// Regular Expressions for parsing tags and attributes
const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeLetters}]*`
const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeRegExp.source}]*`
const qnameCapture = `((?:${ncname}\\:)?${ncname})`
const startTagOpen = new RegExp(`^<${qnameCapture}`)
const startTagClose = /^\s*(\/?)>/
Expand Down
4 changes: 2 additions & 2 deletions src/core/util/lang.js
Expand Up @@ -5,7 +5,7 @@
* using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
* skipping \u10000-\uEFFFF due to it freezing up PhantomJS
*/
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'
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/

/**
* Check if a string starts with $ or _
Expand All @@ -30,7 +30,7 @@ export function def (obj: Object, key: string, val: any, enumerable?: boolean) {
/**
* Parse simple path.
*/
const bailRE = new RegExp(`[^${unicodeLetters}.$_\\d]`)
const bailRE = new RegExp(`[^${unicodeRegExp.source}.$_\\d]`)
export function parsePath (path: string): any {
if (bailRE.test(path)) {
return
Expand Down
4 changes: 2 additions & 2 deletions src/core/util/options.js
Expand Up @@ -3,7 +3,7 @@
import config from '../config'
import { warn } from './debug'
import { set } from '../observer/index'
import { unicodeLetters } from './lang'
import { unicodeRegExp } from './lang'
import { nativeWatch, hasSymbol } from './env'

import {
Expand Down Expand Up @@ -277,7 +277,7 @@ function checkComponents (options: Object) {
}

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

0 comments on commit 67ce99a

Please sign in to comment.