Ignore xhr.status for "file://" requests.

This commit is contained in:
Bryce Gibson 2017-02-15 08:34:40 +11:00
parent 6a617aeb87
commit 27881af668
2 changed files with 20 additions and 1 deletions

View file

@ -2,6 +2,8 @@
var buildQueryString = require("../querystring/build")
var FILE_PROTOCOL_REGEX = new RegExp('^file://', 'i')
module.exports = function($window, Promise) {
var callbackCount = 0
@ -86,7 +88,7 @@ module.exports = function($window, Promise) {
if (xhr.readyState === 4) {
try {
var response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || FILE_PROTOCOL_REGEX.test(args.url)) {
resolve(cast(args.type, response))
}
else {

View file

@ -406,6 +406,23 @@ o.spec("xhr", function() {
done()
})
})
o("doesn't fail on file:// status 0", function(done) {
var s = new Date
mock.$defineRoutes({
"GET /item": function() {
return {status: 0, responseText: JSON.stringify({a: 1})}
}
})
var failed = false
xhr({method: "GET", url: "file:///item"}).catch(function() {
failed = true
}).then(function(data) {
o(failed).equals(false)
o(data).deepEquals({a: 1})
}).then(function() {
done()
})
})
/*o("data maintains after interpolate", function() {
mock.$defineRoutes({
"PUT /items/:x": function() {