aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2015-10-12 19:56:46 +0300
committerOleg Gaidarenko <markelog@gmail.com>2015-10-12 22:38:15 +0300
commit239169bb2ede6ea6287d82d1d13b0c354f451749 (patch)
tree01acc8013b0446a96f05076657bfc5e3babcb0ba /test/unit/ajax.js
parentcb087ce41daa5db4c8db10e586bdc141f953d93d (diff)
downloadjquery-239169bb2ede6ea6287d82d1d13b0c354f451749.tar.gz
jquery-239169bb2ede6ea6287d82d1d13b0c354f451749.zip
Ajax: improve content-type detection
Fixes gh-2584 Closes gh-2643
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r--test/unit/ajax.js104
1 files changed, 103 insertions, 1 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 647958773..ec3e07613 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1794,7 +1794,109 @@ QUnit.module( "ajax", {
}
);
-// //----------- jQuery.ajaxPrefilter()
+ ajaxTest( "gh-2587 - when content-type not xml, but looks like one", 1, function( assert ) {
+ return {
+ url: url( "data/ajax/content-type.php" ),
+ data: {
+ "content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "response": "<test/>"
+ },
+ success: function( result ) {
+ assert.strictEqual(
+ typeof result,
+ "string",
+ "Should handle it as a string, not xml"
+ );
+ }
+ };
+ } );
+
+ ajaxTest( "gh-2587 - when content-type not xml, but looks like one", 1, function( assert ) {
+ return {
+ url: url( "data/ajax/content-type.php" ),
+ data: {
+ "content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "response": "<test/>"
+ },
+ success: function( result ) {
+ assert.strictEqual(
+ typeof result,
+ "string",
+ "Should handle it as a string, not xml"
+ );
+ }
+ };
+ } );
+
+ ajaxTest( "gh-2587 - when content-type not json, but looks like one", 1, function( assert ) {
+ return {
+ url: url( "data/ajax/content-type.php" ),
+ data: {
+ "content-type": "test/jsontest",
+ "response": JSON.stringify({test: "test"})
+ },
+ success: function( result ) {
+ assert.strictEqual(
+ typeof result,
+ "string",
+ "Should handle it as a string, not json"
+ );
+ }
+ };
+ } );
+
+ ajaxTest( "gh-2587 - when content-type not html, but looks like one", 1, function( assert ) {
+ return {
+ url: url( "data/ajax/content-type.php" ),
+ data: {
+ "content-type": "test/htmltest",
+ "response": "<p>test</p>"
+ },
+ success: function( result ) {
+ assert.strictEqual(
+ typeof result,
+ "string",
+ "Should handle it as a string, not html"
+ );
+ }
+ };
+ } );
+
+ ajaxTest( "gh-2587 - when content-type not javascript, but looks like one", 1, function( assert ) {
+ return {
+ url: url( "data/ajax/content-type.php" ),
+ data: {
+ "content-type": "test/testjavascript",
+ "response": "alert(1)"
+ },
+ success: function( result ) {
+ assert.strictEqual(
+ typeof result,
+ "string",
+ "Should handle it as a string, not javascript"
+ );
+ }
+ };
+ } );
+
+ ajaxTest( "gh-2587 - when content-type not ecmascript, but looks like one", 1, function( assert ) {
+ return {
+ url: url( "data/ajax/content-type.php" ),
+ data: {
+ "content-type": "test/testjavascript",
+ "response": "alert(1)"
+ },
+ success: function( result ) {
+ assert.strictEqual(
+ typeof result,
+ "string",
+ "Should handle it as a string, not ecmascript"
+ );
+ }
+ };
+ } );
+
+//----------- jQuery.ajaxPrefilter()
ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, function( assert ) {
return {