Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval Scope #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/reqwest.js
Expand Up @@ -20,6 +20,7 @@
, xmlHttpRequest = 'XMLHttpRequest'
, xDomainRequest = 'XDomainRequest'
, noop = function () {}
, gEval = function(s) { return win.eval.call(win, s) }

, isArray = typeof Array.isArray == 'function'
? Array.isArray
Expand Down Expand Up @@ -306,13 +307,13 @@
switch (type) {
case 'json':
try {
resp = win.JSON ? win.JSON.parse(r) : eval('(' + r + ')')
resp = win.JSON ? win.JSON.parse(r) : gEval('(' + r + ')')
} catch (err) {
return error(resp, 'Could not parse JSON in response', err)
}
break
case 'js':
resp = eval(r)
resp = gEval(r)
break
case 'html':
resp = r
Expand Down Expand Up @@ -341,7 +342,7 @@

function timedOut() {
self._timedOut = true
self.request.abort()
self.request.abort()
}

function error(resp, msg, t) {
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/poison.js
@@ -0,0 +1,5 @@
// Die immediately
self = null

// Common in global scope, e.g. Prism.js+File@
// self = window
16 changes: 16 additions & 0 deletions tests/tests.js
Expand Up @@ -1821,6 +1821,22 @@
})
})

sink('JavaScript', function (test, ok) {
test('Poisoning Scope Variables', function (complete) {
ajax({
url: '/tests/fixtures/poison.js'
, type: 'js'
, success: function () {
ok(
true // Enough to be here
, 'test cannot fail if reached'
)
complete()
}
})
})
})

start()

}(reqwest))