@@ -1630,7 +1630,109 @@ QUnit.module( "ajax", {
16301630 }
16311631 ) ;
16321632
1633- // //----------- jQuery.ajaxPrefilter()
1633+ ajaxTest ( "gh-2587 - when content-type not xml, but looks like one" , 1 , function ( assert ) {
1634+ return {
1635+ url : url ( "data/ajax/content-type.php" ) ,
1636+ data : {
1637+ "content-type" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
1638+ "response" : "<test/>"
1639+ } ,
1640+ success : function ( result ) {
1641+ assert . strictEqual (
1642+ typeof result ,
1643+ "string" ,
1644+ "Should handle it as a string, not xml"
1645+ ) ;
1646+ }
1647+ } ;
1648+ } ) ;
1649+
1650+ ajaxTest ( "gh-2587 - when content-type not xml, but looks like one" , 1 , function ( assert ) {
1651+ return {
1652+ url : url ( "data/ajax/content-type.php" ) ,
1653+ data : {
1654+ "content-type" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
1655+ "response" : "<test/>"
1656+ } ,
1657+ success : function ( result ) {
1658+ assert . strictEqual (
1659+ typeof result ,
1660+ "string" ,
1661+ "Should handle it as a string, not xml"
1662+ ) ;
1663+ }
1664+ } ;
1665+ } ) ;
1666+
1667+ ajaxTest ( "gh-2587 - when content-type not json, but looks like one" , 1 , function ( assert ) {
1668+ return {
1669+ url : url ( "data/ajax/content-type.php" ) ,
1670+ data : {
1671+ "content-type" : "test/jsontest" ,
1672+ "response" : JSON . stringify ( { test : "test" } )
1673+ } ,
1674+ success : function ( result ) {
1675+ assert . strictEqual (
1676+ typeof result ,
1677+ "string" ,
1678+ "Should handle it as a string, not json"
1679+ ) ;
1680+ }
1681+ } ;
1682+ } ) ;
1683+
1684+ ajaxTest ( "gh-2587 - when content-type not html, but looks like one" , 1 , function ( assert ) {
1685+ return {
1686+ url : url ( "data/ajax/content-type.php" ) ,
1687+ data : {
1688+ "content-type" : "test/htmltest" ,
1689+ "response" : "<p>test</p>"
1690+ } ,
1691+ success : function ( result ) {
1692+ assert . strictEqual (
1693+ typeof result ,
1694+ "string" ,
1695+ "Should handle it as a string, not html"
1696+ ) ;
1697+ }
1698+ } ;
1699+ } ) ;
1700+
1701+ ajaxTest ( "gh-2587 - when content-type not javascript, but looks like one" , 1 , function ( assert ) {
1702+ return {
1703+ url : url ( "data/ajax/content-type.php" ) ,
1704+ data : {
1705+ "content-type" : "test/testjavascript" ,
1706+ "response" : "alert(1)"
1707+ } ,
1708+ success : function ( result ) {
1709+ assert . strictEqual (
1710+ typeof result ,
1711+ "string" ,
1712+ "Should handle it as a string, not javascript"
1713+ ) ;
1714+ }
1715+ } ;
1716+ } ) ;
1717+
1718+ ajaxTest ( "gh-2587 - when content-type not ecmascript, but looks like one" , 1 , function ( assert ) {
1719+ return {
1720+ url : url ( "data/ajax/content-type.php" ) ,
1721+ data : {
1722+ "content-type" : "test/testjavascript" ,
1723+ "response" : "alert(1)"
1724+ } ,
1725+ success : function ( result ) {
1726+ assert . strictEqual (
1727+ typeof result ,
1728+ "string" ,
1729+ "Should handle it as a string, not ecmascript"
1730+ ) ;
1731+ }
1732+ } ;
1733+ } ) ;
1734+
1735+ //----------- jQuery.ajaxPrefilter()
16341736
16351737 ajaxTest ( "jQuery.ajaxPrefilter() - abort" , 1 , function ( assert ) {
16361738 return {
0 commit comments