-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Description
Description
Upgrading from version 2 to version 3 of jQuery we see uncaught exceptions being thrown in unit test cases that cause certain unit tests to fail due to these uncaught exceptions. This causes is a backwards incompatibility to adopt version 3 we need to hack our unit test to ignore certain uncaught exceptions or otherwise detect the test environment to avoid requests to URLs that don't work in this environment. It would be good if we can fix that incompatibility since it seems easily avoidable.
Steps to Reproduce:
Run something like this:
jQuery.ajax({ url: "./someInvalidUrl", dataType: "jsonp" });
Assume the URL goes to some place which responds with 404 status and a Content-Type: text/html
response header and responseText with HTML content.
Expected Behavior:
No uncaught exceptions should be observed.
Actual Behavior:
An uncaught exception is thrown attempting to evaluate the response text, which is not a script but HTML content.
Uncaught SyntaxError: Unexpected token '<'
at b (jquery.min.js:2:866)
at Function.globalEval (jquery.min.js:2:2905)
at text script (jquery.min.js:2:83080)
at jquery.min.js:2:79470
at l (jquery.min.js:2:79587)
at XMLHttpRequest.<anonymous> (jquery.min.js:2:82355)
Suggested Solution:
Do not attempt to DOMEval a 404 response during jsonp evaluation, an additional clue that this response is not a script is the content type response header. Either one should be sufficient.
Link to test case
Failure in jQuery 3.X: https://jsfiddle.net/5o94ujsL/
Same thin in jQuery 2.X: https://jsfiddle.net/m3dp2zbt/
In both cases the global error handler should not be invoked, but we see in jquery 3 that the global error handler is invoked because of the following stack trace:
Uncaught SyntaxError: Unexpected token '<'
at b (jquery.min.js:2:866)
at Function.globalEval (jquery.min.js:2:2905)
at text script (jquery.min.js:2:83080)
at jquery.min.js:2:79470
at l (jquery.min.js:2:79587)
at XMLHttpRequest.<anonymous> (jquery.min.js:2:82355)