-
Notifications
You must be signed in to change notification settings - Fork 162
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
fix fetch API rasies TypeError when argument is URL object
(close #1613)
#1623
Conversation
❌ Tests for the commit 984020d have failed. See details: |
src/client/sandbox/fetch.js
Outdated
@@ -53,7 +55,24 @@ export default class FetchSandbox extends SandboxBase { | |||
} | |||
|
|||
static _isValidRequestArgs (args) { | |||
return typeof args[0] === 'string' || isFetchRequest(args[0]); | |||
if (typeof args[0] === 'string' || isFetchRequest(args[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad design. _isValidRequestArgs
should not modify the arguments.
Rewrite as the following:
return typeof args[0] === 'string' || isFetchRequest(args[0]) || objectWithToStringMethod;
Move argument processing logic for null
, undefined
and custom object with toString
method to FetchSandbox._processArguments(args)
.
return this.url; | ||
} | ||
}, | ||
expectedUrl: 'https://example.com/some-path' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test for object without toString
method
❌ Tests for the commit 4e699bb have failed. See details: |
❌ Tests for the commit 931baa9 have failed. See details: |
✅ Tests for the commit 1029adf have passed. See details: |
}); | ||
}; | ||
|
||
var promises = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var cases = [
checkArg({
toString: function () {
return {};
}
})
];
❌ Tests for the commit ccb2aeb have failed. See details: |
❌ Tests for the commit f9bed6d have failed. See details: |
@testcafe-build-bot \retest |
❌ Tests for the commit f9bed6d have failed. See details: |
❌ Tests for the commit 8521d2b have failed. See details: |
✅ Tests for the commit c7a2e68 have passed. See details: |
✅ Tests for the commit d02d5b9 have passed. See details: |
❌ Tests for the commit 9c3493f have failed. See details: |
@testcafe-build-bot \retest |
❌ Tests for the commit 9c3493f have failed. See details: |
✅ Tests for the commit 864bd6d have passed. See details: |
❌ Tests for the commit 2d87ed8 have failed. See details: |
❌ Tests for the commit 7f3566a have failed. See details: |
@testcafe-build-bot \retest |
❌ Tests for the commit 7f3566a have failed. See details: |
❌ Tests for the commit aa0d6dd have failed. See details: |
fetch API rasies TypeError when argument is URL object
(close #1613)fetch API rasies TypeError when argument is URL object
(close #1613)
❌ Tests for the commit 33ee438 have failed. See details: |
@testcafe-build-bot \retest |
✅ Tests for the commit 33ee438 have passed. See details: |
@@ -61,6 +61,10 @@ export default class LocationWrapper extends EventEmitter { | |||
return ensureTrailingSlash(href, locationUrl); | |||
}; | |||
const getProxiedHref = href => { | |||
// NOTE: we must convert url-object to 'string' (GH-1613) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
src/client/sandbox/fetch.js
Outdated
if (inputIsString) { | ||
args[0] = getProxyUrl(input); | ||
if (!inputIsFetchRequest) { | ||
// NOTE: we must convert url-object to 'string' (GH-1613) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
src/client/sandbox/xhr.js
Outdated
const url = arguments[1]; | ||
const urlIsString = typeof input === 'string'; | ||
|
||
// NOTE: we must convert url-object to 'string' (GH-1613) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
❌ Tests for the commit 7975445 have failed. See details: |
src/client/sandbox/fetch.js
Outdated
return nativeMethods.fetch.apply(this); | ||
|
||
if (!FetchSandbox._requestIsValid(args)) | ||
return sandbox.window.Promise.reject(new TypeError()); | ||
// NOTE: If the input argument(args[0]) is not a `string` and is not a `Request` object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment
|
||
FetchSandbox._processArguments(args); | ||
if (!FetchSandbox._sameOriginCheck(args)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move FetchSandbox._sameOriginCheck
to the FetchSandbox._processArguments
@@ -192,6 +192,204 @@ test('special pages (GH-339)', function () { | |||
destLocation.forceLocation(storedForcedLocation); | |||
}); | |||
|
|||
test('should process some url types in locationWrapper (href, replace, assign) (GH-1613)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('different url types for locationWrapper methods (href, replace, assign) (GH-1613)'
}); | ||
}); | ||
|
||
test('should throwing an error on invalid url-object in locationWrapper (href, replace, assign) (GH-1613)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('throwing errors on calling locationWrapper methods (href, replace, assign) with invalid arguments
} | ||
}); | ||
|
||
test('should process some url types in the "location" property (GH-1613)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('different url types for "location" property (GH-1613)')
}); | ||
}; | ||
|
||
var checkIframesLocation = function (nativeIframeUrl, processedIframeUrl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var checkLocationAssignment = ...
@@ -62,6 +62,52 @@ if (window.fetch) { | |||
}); | |||
}); | |||
|
|||
test('should process some argument types (GH-1613)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
different url types for 'fetch' (GH-1613)
@@ -76,6 +78,66 @@ test('toString, instanceof, constructor and static properties', function () { | |||
strictEqual(XMLHttpRequest.DONE, nativeMethods.XMLHttpRequest.DONE); | |||
}); | |||
|
|||
test('overridden "open" function should process some url argument types before the native "XMLHttpRequest.open" method calling (GH-1613)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('different url types for xhr.open method (GH-1613)')
nativeMethods.xhrOpen = storedNativeXhrOpen; | ||
}); | ||
|
||
test('should throwing an error on invalid calling "open" (GH-1613)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('should throwing an error on invalid calling "open" method (GH-1613)'
start(); | ||
} | ||
// NOTE: IE11 doesn't support 'XMLHttpRequest.responseURL' | ||
if (browserUtils.isIE11) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this condition need?
…evExpress#1613) (DevExpress#1623) * fix `fetch API rasies TypeError when argument is URL object` * requested changes, fix Safari case * refactoring * requested changes * requested changes * requested changes: fix tests * add URL test case * xhr, location.href, location.assign, location.replace cases * requested changes: fix xhr.open test, remove unnecessary testcase in window-test.js * requested changes: refactor xhr.open test * fix location property case * try to fix tests * try to fix tests * fix location property test * try to fix location property test * try to fix location property test * fix double quotation in location property test * requested changes * requested changes * restore xhr.responseURL test
fetch
supports the following browsers: Chrome, Firefox, Edge, Safari.References
#1613
#939
Changes
fetch()
src/client/sandbox/fetch.js:If the input argument(args[0]) is not a
string
and is not aRequest
object,we are trying to convert the input argument to
string
primitive value usingString()
.This approach helps us simulate the browsers behavior by throwing the 'TypeError' exception
if the input object can not be converted to a primitive value.
XMLHttpRequest
: convert url argument to string beforegetProxyUrl
. Fix test/client/before-test.jscheckNativeFunctionCalling
.locationWrapper
(href
setter,assgin
,replace
): convert url argument to string.location
property case. Add routes in test/client/config-qunit-server-app.js for iframe loading in IE 11 (location
property test)Fix "request promise should be rejected on invalid calling (GH-939)" test
Browsers process all of these arguments in
fetch
withoutPromise
rejection:Simple example:
Safari processed
fetch()
withoutPromise
rejectionBrowsers process inaccessible
null
andundefined
arguments withoutPromise
rejectionObject
in thefetch
first argumentURL
:Object
withouttoString
method:Object
withtoString
method: