@@ -1794,7 +1794,109 @@ QUnit.module( "ajax", {
17941794 }
17951795 ) ;
17961796
1797- // //----------- jQuery.ajaxPrefilter()
1797+ ajaxTest ( "gh-2587 - when content-type not xml, but looks like one" , 1 , function ( assert ) {
1798+ return {
1799+ url : url ( "data/ajax/content-type.php" ) ,
1800+ data : {
1801+ "content-type" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
1802+ "response" : "<test/>"
1803+ } ,
1804+ success : function ( result ) {
1805+ assert . strictEqual (
1806+ typeof result ,
1807+ "string" ,
1808+ "Should handle it as a string, not xml"
1809+ ) ;
1810+ }
1811+ } ;
1812+ } ) ;
1813+
1814+ ajaxTest ( "gh-2587 - when content-type not xml, but looks like one" , 1 , function ( assert ) {
1815+ return {
1816+ url : url ( "data/ajax/content-type.php" ) ,
1817+ data : {
1818+ "content-type" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
1819+ "response" : "<test/>"
1820+ } ,
1821+ success : function ( result ) {
1822+ assert . strictEqual (
1823+ typeof result ,
1824+ "string" ,
1825+ "Should handle it as a string, not xml"
1826+ ) ;
1827+ }
1828+ } ;
1829+ } ) ;
1830+
1831+ ajaxTest ( "gh-2587 - when content-type not json, but looks like one" , 1 , function ( assert ) {
1832+ return {
1833+ url : url ( "data/ajax/content-type.php" ) ,
1834+ data : {
1835+ "content-type" : "test/jsontest" ,
1836+ "response" : JSON . stringify ( { test : "test" } )
1837+ } ,
1838+ success : function ( result ) {
1839+ assert . strictEqual (
1840+ typeof result ,
1841+ "string" ,
1842+ "Should handle it as a string, not json"
1843+ ) ;
1844+ }
1845+ } ;
1846+ } ) ;
1847+
1848+ ajaxTest ( "gh-2587 - when content-type not html, but looks like one" , 1 , function ( assert ) {
1849+ return {
1850+ url : url ( "data/ajax/content-type.php" ) ,
1851+ data : {
1852+ "content-type" : "test/htmltest" ,
1853+ "response" : "<p>test</p>"
1854+ } ,
1855+ success : function ( result ) {
1856+ assert . strictEqual (
1857+ typeof result ,
1858+ "string" ,
1859+ "Should handle it as a string, not html"
1860+ ) ;
1861+ }
1862+ } ;
1863+ } ) ;
1864+
1865+ ajaxTest ( "gh-2587 - when content-type not javascript, but looks like one" , 1 , function ( assert ) {
1866+ return {
1867+ url : url ( "data/ajax/content-type.php" ) ,
1868+ data : {
1869+ "content-type" : "test/testjavascript" ,
1870+ "response" : "alert(1)"
1871+ } ,
1872+ success : function ( result ) {
1873+ assert . strictEqual (
1874+ typeof result ,
1875+ "string" ,
1876+ "Should handle it as a string, not javascript"
1877+ ) ;
1878+ }
1879+ } ;
1880+ } ) ;
1881+
1882+ ajaxTest ( "gh-2587 - when content-type not ecmascript, but looks like one" , 1 , function ( assert ) {
1883+ return {
1884+ url : url ( "data/ajax/content-type.php" ) ,
1885+ data : {
1886+ "content-type" : "test/testjavascript" ,
1887+ "response" : "alert(1)"
1888+ } ,
1889+ success : function ( result ) {
1890+ assert . strictEqual (
1891+ typeof result ,
1892+ "string" ,
1893+ "Should handle it as a string, not ecmascript"
1894+ ) ;
1895+ }
1896+ } ;
1897+ } ) ;
1898+
1899+ //----------- jQuery.ajaxPrefilter()
17981900
17991901 ajaxTest ( "jQuery.ajaxPrefilter() - abort" , 1 , function ( assert ) {
18001902 return {
0 commit comments