File tree 3 files changed +17
-8
lines changed
test/unit/features/options
3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,10 @@ import { isNonPhrasingTag } from 'web/compiler/util'
14
14
15
15
// Regular Expressions for parsing tags and attributes
16
16
const attribute = / ^ \s * ( [ ^ \s " ' < > \/ = ] + ) (?: \s * ( = ) \s * (?: " ( [ ^ " ] * ) " + | ' ( [ ^ ' ] * ) ' + | ( [ ^ \s " ' = < > ` ] + ) ) ) ? /
17
- // could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
18
- // but for Vue templates we can enforce a simple charset
19
- const ncname = '[a-zA-Z_][\\w\\-\\.]*'
17
+ // use https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
18
+ // except \u10000-\uEFFFF because of performance problem
19
+ export const pcenchars = '[\\-\\.0-9_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]'
20
+ const ncname = `[a-zA-Z_]${ pcenchars } *`
20
21
const qnameCapture = `((?:${ ncname } \\:)?${ ncname } )`
21
22
const startTagOpen = new RegExp ( `^<${ qnameCapture } ` )
22
23
const startTagClose = / ^ \s * ( \/ ? ) > /
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import config from '../config'
4
4
import { warn } from './debug'
5
5
import { nativeWatch } from './env'
6
6
import { set } from '../observer/index'
7
+ import { pcenchars } from '../../compiler/parser/html-parser'
7
8
8
9
import {
9
10
ASSET_TYPES ,
@@ -253,11 +254,10 @@ function checkComponents (options: Object) {
253
254
}
254
255
255
256
export function validateComponentName ( name : string ) {
256
- if ( ! / ^ [ a - z A - Z ] [ \w - ] * $ / . test ( name ) ) {
257
+ if ( ! new RegExp ( ` ^[a-zA-Z]${ pcenchars } *$` ) . test ( name ) ) {
257
258
warn (
258
259
'Invalid component name: "' + name + '". Component names ' +
259
- 'can only contain alphanumeric characters and the hyphen, ' +
260
- 'and must start with a letter.'
260
+ 'should conform to valid custom element name in html5 specification.'
261
261
)
262
262
}
263
263
if ( isBuiltInTag ( name ) || config . isReservedTag ( name ) ) {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ describe('Options name', () => {
15
15
} )
16
16
17
17
/* eslint-disable */
18
- expect ( `Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter. ` )
18
+ expect ( `Invalid component name: "Hyper*Vue".` )
19
19
. toHaveBeenWarned ( )
20
20
/* eslint-enable */
21
21
@@ -24,7 +24,7 @@ describe('Options name', () => {
24
24
} )
25
25
26
26
/* eslint-disable */
27
- expect ( `Invalid component name: "2Cool2BValid". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter. ` )
27
+ expect ( `Invalid component name: "2Cool2BValid".` )
28
28
. toHaveBeenWarned ( )
29
29
/* eslint-enable */
30
30
} )
@@ -37,4 +37,12 @@ describe('Options name', () => {
37
37
expect ( SuperComponent . options . components [ 'SuperVue' ] ) . toEqual ( SuperComponent )
38
38
expect ( SuperComponent . options . components [ 'super-component' ] ) . toEqual ( SuperComponent )
39
39
} )
40
+
41
+ it ( 'should allow all potential custom element name for component name including non-alphanumeric characters' , ( ) => {
42
+ Vue . extend ( {
43
+ name : 'my-컴포넌트'
44
+ } )
45
+
46
+ expect ( `Invalid component name` ) . not . toHaveBeenWarned ( )
47
+ } )
40
48
} )
You can’t perform that action at this time.
0 commit comments