]> source.dussan.org Git - jquery.git/commitdiff
Fixes #8297. Makes sure response headers with empty values are handled properly and...
authorjaubourg <j@ubourg.net>
Thu, 17 Feb 2011 16:03:09 +0000 (17:03 +0100)
committerjaubourg <j@ubourg.net>
Thu, 17 Feb 2011 16:03:09 +0000 (17:03 +0100)
src/ajax.js
test/data/headers.php
test/unit/ajax.js

index 76a2dc81236923dabd9a01073b8e932ce379429a..6414e8c2990e8e9d07a4cfce056a1b896c1b2522 100644 (file)
@@ -4,7 +4,7 @@ var r20 = /%20/g,
        rbracket = /\[\]$/,
        rCRLF = /\r?\n/g,
        rhash = /#.*$/,
-       rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL
+       rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
        rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
        // #7653, #8125, #8152: local protocol detection
        rlocalProtocol = /(?:^file|^widget|\-extension):$/,
@@ -439,7 +439,7 @@ jQuery.extend({
                                                }
                                                match = responseHeaders[ key.toLowerCase() ];
                                        }
-                                       return match || null;
+                                       return match === undefined ? null : match;
                                },
 
                                // Overrides response content-type header
index d500b16f45436fce8dc780b695adf4b8d4782f88..968f13f19abc487dcc2bfa4c7a03603089ad4690 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
 header( "Sample-Header: Hello World" );
+header( "Empty-Header: " );
+header( "Sample-Header2: Hello World 2" );
 
 $headers = array();
 
index 80da7f8f88734bf59b190ca0862c71f002aa0192..335c2ac4d310348eda37d17a602b9a4d63940c2a 100644 (file)
@@ -344,7 +344,7 @@ test(".ajax() - retry with jQuery.ajax( this )", function() {
 
 test(".ajax() - headers" , function() {
 
-       expect( 2 );
+       expect( 4 );
 
        stop();
 
@@ -376,8 +376,14 @@ test(".ajax() - headers" , function() {
                        tmp.push(  "ajax-send: test\n" );
                        tmp = tmp.join( "" );
 
-                       equals( data , tmp , "Headers were sent" );
-                       equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
+                       strictEqual( data , tmp , "Headers were sent" );
+                       strictEqual( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
+                       if ( jQuery.browser.mozilla ) {
+                               ok( true, "Firefox doesn't support empty headers" );
+                       } else {
+                               strictEqual( xhr.getResponseHeader( "Empty-Header" ) , "" , "Empty header received" );
+                       }
+                       strictEqual( xhr.getResponseHeader( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" );
                },
                error: function(){ ok(false, "error"); }