Skip to content

Commit 97754de

Browse files
committed
check invalid v-bind in production build as well
1 parent 6725827 commit 97754de

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

src/compiler/compile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,10 @@ function compileDirectives (attrs, options) {
560560
attr = attrs[i]
561561
name = attr.name
562562
raw = value = attr.value
563+
tokens = textParser.parse(value)
563564

564565
// attribute interpolations
565-
if (tokens = textParser.parse(value)) {
566+
if (tokens) {
566567
value = textParser.tokensToExp(tokens)
567568
pushDir('bind', publicDirectives.bind, {
568569
arg: name,

src/directives/public/bind.js

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@ module.exports = {
2424

2525
priority: 850,
2626

27+
bind: function () {
28+
var attr = this.arg
29+
// handle interpolation bindings
30+
if (this.descriptor.interp) {
31+
// only allow binding on native attributes
32+
if (!(
33+
// class is allowed globally
34+
attr === 'class' ||
35+
// data attributes are allowed globally
36+
/^data-/.test(attr) ||
37+
// for available
38+
(attr === 'for' && 'htmlFor' in this.el) ||
39+
// camelized prop available
40+
_.camelize(attr) in this.el
41+
)) {
42+
process.env.NODE_ENV !== 'production' && _.warn(
43+
attr + '="' + this.descriptor.raw + '": ' +
44+
'attribute interpolation is allowed only ' +
45+
'in valid native attributes. "' + attr + '" ' +
46+
'is not a valid attribute on <' + this.el.tagName.toLowerCase() + '>.'
47+
)
48+
this.invalid = true
49+
}
50+
51+
if (process.env.NODE_ENV !== 'production') {
52+
var raw = attr + '="' + this.descriptor.raw + '": '
53+
// warn src
54+
if (attr === 'src') {
55+
_.warn(
56+
raw + 'interpolation in "src" attribute will cause ' +
57+
'a 404 request. Use v-bind:src instead.'
58+
)
59+
}
60+
61+
// warn style
62+
if (attr === 'style') {
63+
_.warn(
64+
raw + 'interpolation in "style" attribtue will cause ' +
65+
'the attribtue to be discarded in Internet Explorer. ' +
66+
'Use v-bind:style instead.'
67+
)
68+
}
69+
}
70+
}
71+
},
72+
2773
update: function (value) {
2874
if (this.invalid) return
2975
var attr = this.arg
@@ -49,50 +95,3 @@ module.exports = {
4995
}
5096
}
5197
}
52-
53-
if (process.env.NODE_ENV !== 'production') {
54-
module.exports.bind = function () {
55-
var attr = this.arg
56-
// handle interpolation bindings
57-
if (this.descriptor.interp) {
58-
var raw = attr + '="' + this.descriptor.raw + '": '
59-
// only allow binding on native attributes
60-
if (
61-
// data attributes are allowed
62-
!(/^data-/.test(attr)) &&
63-
// class is allowed
64-
!(attr === 'class') &&
65-
(
66-
// label for
67-
(attr === 'for' && !('htmlFor' in this.el)) ||
68-
// other native attributes
69-
!(_.camelize(attr) in this.el)
70-
)
71-
) {
72-
_.warn(
73-
raw + 'attribute interpolation is allowed only ' +
74-
'in valid native attributes. "' + attr + '" ' +
75-
'is not a valid attribute on <' + this.el.tagName.toLowerCase() + '>.'
76-
)
77-
this.invalid = true
78-
}
79-
80-
// warn src
81-
if (attr === 'src') {
82-
_.warn(
83-
raw + 'interpolation in "src" attribute will cause ' +
84-
'a 404 request. Use v-bind:src instead.'
85-
)
86-
}
87-
88-
// warn style
89-
if (attr === 'style') {
90-
_.warn(
91-
raw + 'interpolation in "style" attribtue will cause ' +
92-
'the attribtue to be discarded in Internet Explorer. ' +
93-
'Use v-bind:style instead.'
94-
)
95-
}
96-
}
97-
}
98-
}

0 commit comments

Comments
 (0)