Skip to content

Commit 78a8e66

Browse files
committed
apply csp patch
1 parent df71954 commit 78a8e66

File tree

10 files changed

+4790
-99
lines changed

10 files changed

+4790
-99
lines changed

build/grunt-tasks/build.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@
33
*/
44

55
module.exports = function (grunt) {
6-
grunt.registerTask('build', function () {
6+
7+
grunt.registerTask('build-vendor', function () {
8+
var webpack = require('webpack')
9+
webpack({
10+
entry: './node_modules/notevil/index.js',
11+
output: {
12+
path: './vendor',
13+
filename: 'notevil.js',
14+
library: 'notevil',
15+
libraryTarget: 'commonjs2'
16+
}
17+
}, this.async())
18+
})
19+
20+
grunt.registerTask('build-self', function () {
721

822
var done = this.async()
923
var fs = require('fs')
@@ -66,4 +80,6 @@ module.exports = function (grunt) {
6680
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
6781
}
6882
})
83+
84+
grunt.registerTask('build', ['build-vendor', 'build-self'])
6985
}

gruntfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ module.exports = function (grunt) {
2424
files: [
2525
'test/unit/lib/util.js',
2626
'test/unit/lib/jquery.js',
27+
'vendor/*.js',
2728
'src/**/*.js',
2829
'test/unit/specs/**/*.js'
2930
],
3031
preprocessors: {
32+
'vendor/*.js': ['commonjs'],
3133
'src/**/*.js': ['commonjs'],
3234
'test/unit/specs/**/*.js': ['commonjs']
3335
},
@@ -44,6 +46,7 @@ module.exports = function (grunt) {
4446
browsers: ['PhantomJS'],
4547
reporters: ['progress', 'coverage'],
4648
preprocessors: {
49+
'vendor/*.js': ['commonjs'],
4750
'src/**/*.js': ['commonjs', 'coverage'],
4851
'test/unit/specs/**/*.js': ['commonjs']
4952
},
@@ -83,7 +86,7 @@ module.exports = function (grunt) {
8386
grunt.registerTask('unit', ['karma:browsers'])
8487
grunt.registerTask('cover', ['karma:coverage'])
8588
grunt.registerTask('test', ['unit', 'cover', 'casper'])
86-
grunt.registerTask('sauce', ['karma:sauce1', 'karma:sauce2', 'karma:sauce3'])
89+
grunt.registerTask('sauce', ['karma:sauce1']) // CSP: only need Chrome and Firefox
8790
grunt.registerTask('default', ['eslint', 'build', 'test'])
8891

8992
// CI

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"karma-phantomjs-launcher": "^0.2.1",
4747
"karma-safari-launcher": "^0.1.1",
4848
"karma-sauce-launcher": "^0.3.0",
49+
"notevil": "^1.0.0",
4950
"phantomjs": "^1.9.17",
5051
"semver": "^5.0.1",
5152
"shell-task": "^1.0.0",

src/api/global.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ exports.extend = function (extendOptions) {
4949
return extendOptions._Ctor
5050
}
5151
var name = extendOptions.name || Super.options.name
52-
var Sub = createClass(name || 'VueComponent')
52+
var Sub = function VueComponent (options) {
53+
_.Vue.call(this, options)
54+
}
5355
Sub.prototype = Object.create(Super.prototype)
5456
Sub.prototype.constructor = Sub
5557
Sub.cid = cid++
@@ -76,22 +78,6 @@ exports.extend = function (extendOptions) {
7678
return Sub
7779
}
7880

79-
/**
80-
* A function that returns a sub-class constructor with the
81-
* given name. This gives us much nicer output when
82-
* logging instances in the console.
83-
*
84-
* @param {String} name
85-
* @return {Function}
86-
*/
87-
88-
function createClass (name) {
89-
return new Function(
90-
'return function ' + _.classify(name) +
91-
' (options) { this._init(options) }'
92-
)()
93-
}
94-
9581
/**
9682
* Plugin system
9783
*

src/parsers/expression.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var _ = require('../util')
22
var Path = require('./path')
33
var Cache = require('../cache')
4+
var notevil = require('../../vendor/notevil')
45
var expressionCache = new Cache(1000)
56

67
var allowedKeywords =
@@ -173,7 +174,13 @@ function compilePathFns (exp) {
173174

174175
function makeGetter (body) {
175176
try {
176-
return new Function('scope', 'return ' + body + ';')
177+
var fn = notevil.Function(
178+
'scope', 'Math',
179+
'return ' + body + ';'
180+
)
181+
return function (scope) {
182+
return fn.call(this, scope, Math)
183+
}
177184
} catch (e) {
178185
process.env.NODE_ENV !== 'production' && _.warn(
179186
'Invalid expression. ' +
@@ -198,7 +205,15 @@ function makeGetter (body) {
198205

199206
function makeSetter (body) {
200207
try {
201-
return new Function('scope', 'value', body + '=value;')
208+
var fn = notevil.Function(
209+
'scope', 'value', 'Math',
210+
body + ' = value;'
211+
)
212+
return function (scope, value) {
213+
try {
214+
fn.call(this, scope, value, Math)
215+
} catch (e) {}
216+
}
202217
} catch (e) {
203218
process.env.NODE_ENV !== 'production' && _.warn(
204219
'Invalid setter function body: ' + body

src/parsers/path.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var _ = require('../util')
22
var Cache = require('../cache')
33
var pathCache = new Cache(1000)
4-
var identRE = exports.identRE = /^[$_a-zA-Z]+[\w$]*$/
4+
exports.identRE = /^[$_a-zA-Z]+[\w$]*$/
55

66
// actions
77
var APPEND = 0
@@ -228,25 +228,6 @@ function parsePath (path) {
228228
}
229229
}
230230

231-
/**
232-
* Format a accessor segment based on its type.
233-
*
234-
* @param {String} key
235-
* @return {Boolean}
236-
*/
237-
238-
function formatAccessor (key) {
239-
if (identRE.test(key)) { // identifier
240-
return '.' + key
241-
} else if (+key === key >>> 0) { // bracket index
242-
return '[' + key + ']'
243-
} else if (key.charAt(0) === '*') {
244-
return '[o' + formatAccessor(key.slice(1)) + ']'
245-
} else { // bracket string
246-
return '["' + key.replace(/"/g, '\\"') + '"]'
247-
}
248-
}
249-
250231
/**
251232
* Compiles a getter function with a fixed path.
252233
* The fixed path getter supresses errors.
@@ -256,8 +237,22 @@ function formatAccessor (key) {
256237
*/
257238

258239
exports.compileGetter = function (path) {
259-
var body = 'return o' + path.map(formatAccessor).join('')
260-
return new Function('o', body)
240+
return function get (obj) {
241+
var original = obj
242+
var segment
243+
for (var i = 0, l = path.length; i < l; i++) {
244+
segment = path[i]
245+
if (segment.charAt(0) === '*') {
246+
segment = original[segment.slice(1)]
247+
}
248+
obj = obj[segment]
249+
if (i === l - 1) {
250+
return obj
251+
} else if (!_.isObject(obj)) {
252+
return
253+
}
254+
}
255+
}
261256
}
262257

263258
/**

test/unit/specs/api/data_spec.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,6 @@ describe('Data API', function () {
4949
expect(hasWarned(_, 'Consider pre-initializing')).toBe(true)
5050
})
5151

52-
it('$set invalid', function () {
53-
// invalid, should throw
54-
if (leftHandThrows()) {
55-
// if creating a function with invalid left hand
56-
// expression throws, the exp parser will catch the
57-
// error and warn.
58-
vm.$set('c + d', 1)
59-
expect(hasWarned(_, 'Invalid setter function body')).toBe(true)
60-
} else {
61-
// otherwise it will throw when calling the setter.
62-
expect(function () {
63-
try {
64-
vm.$set('c + d', 1)
65-
} catch (e) {
66-
return true
67-
}
68-
}()).toBe(true)
69-
}
70-
})
71-
7252
it('$delete', function () {
7353
vm._digest = jasmine.createSpy()
7454
vm.$delete('a')
@@ -182,16 +162,3 @@ describe('Data API', function () {
182162
}
183163

184164
})
185-
186-
/**
187-
* check if creating a new Function with invalid left-hand
188-
* assignment would throw
189-
*/
190-
191-
function leftHandThrows () {
192-
try {
193-
new Function('a + b = 1')
194-
} catch (e) {
195-
return true
196-
}
197-
}

test/unit/specs/api/global_spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ describe('Global API', function () {
1919
expect(Test.options.a).toBe(1)
2020
expect(Test.options.b).toBe(2)
2121
expect(Test.super).toBe(Vue)
22-
// function.name is not available in IE
23-
expect(Test.toString().match(/^function Test\s?\(/)).toBeTruthy()
2422
var t = new Test({
2523
a: 2
2624
})

test/unit/specs/parsers/expression_spec.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,12 @@ var testCases = [
198198
expected: true,
199199
paths: []
200200
},
201-
{
202-
// Date global
203-
exp: 'Date.now() > new Date("2000-01-01")',
204-
scope: {},
205-
expected: true,
206-
paths: []
207-
},
208201
// typeof operator
209202
{
210203
exp: 'typeof test === "string"',
211204
scope: { test: '123' },
212205
expected: true,
213206
paths: ['test']
214-
},
215-
// isNaN
216-
{
217-
exp: 'isNaN(a)',
218-
scope: { a: 2 },
219-
expected: false,
220-
paths: ['a']
221-
},
222-
// parseFloat & parseInt
223-
{
224-
exp: 'parseInt(a, 10) + parseFloat(b)',
225-
scope: { a: 2.33, b: '3.45' },
226-
expected: 5.45,
227-
paths: ['a', 'b']
228207
}
229208
]
230209

0 commit comments

Comments
 (0)