Skip to content

Commit f887ed4

Browse files
committed
v-bind: simplify global allowed attribute check
1 parent 0f249f2 commit f887ed4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/directives/public/bind.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ var modelProps = {
2020
'false-value': '_falseValue'
2121
}
2222

23+
// regex to test for globally allowed attributes:
24+
// - class
25+
// - data-*
26+
// - aria-*
27+
// - role
28+
var globalAllowedAttrRE = /^class$|^role$|^data-|^aria-/
29+
2330
module.exports = {
2431

2532
priority: 850,
@@ -30,17 +37,13 @@ module.exports = {
3037
if (this.descriptor.interp) {
3138
// only allow binding on native attributes
3239
if (!(
33-
// class is allowed globally
34-
attr === 'class' ||
35-
// data attributes are allowed globally
36-
/^data-/.test(attr) ||
37-
// aria attributes are allowed globally
38-
/^aria-/.test(attr) ||
39-
// role available
40-
(attr === 'role') ||
41-
// for available
40+
// globally allowed attributes
41+
globalAllowedAttrRE.test(attr) ||
42+
// check if "for" is available on current element.
43+
// the corresponding property is a special case.
4244
(attr === 'for' && 'htmlFor' in this.el) ||
43-
// camelized prop available
45+
// other attributes: check if a camelized property
46+
// is available on the element
4447
_.camelize(attr) in this.el
4548
)) {
4649
process.env.NODE_ENV !== 'production' && _.warn(

0 commit comments

Comments
 (0)