Skip to content

Commit 714ae37

Browse files
committed
Fixes #8509. Makes URL regexp less overzealous and ensures it recognizes URL schemes which do not contain a conformant hierarchical structure ( as per section 2.1.2 of http://www.ietf.org/rfc/rfc2718.txt ). Also adds about: and adobe air's app: and app-storage: to the list of local protocols and provides a failover in case document.location is illformed. Unit test added.
1 parent 6c124d3 commit 714ae37

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/ajax.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var r20 = /%20/g,
77
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
88
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
99
// #7653, #8125, #8152: local protocol detection
10-
rlocalProtocol = /(?:^file|^widget|\-extension):$/,
10+
rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/,
1111
rnoContent = /^(?:GET|HEAD)$/,
1212
rprotocol = /^\/\//,
1313
rquery = /\?/,
@@ -19,7 +19,7 @@ var r20 = /%20/g,
1919
rucHeadersFunc = function( _, $1, $2 ) {
2020
return $1 + $2.toUpperCase();
2121
},
22-
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?|\/[^\/])/,
22+
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
2323

2424
// Keep a copy of the old load method
2525
_load = jQuery.fn.load,
@@ -61,7 +61,7 @@ try {
6161
}
6262

6363
// Segment location into parts
64-
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() );
64+
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
6565

6666
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
6767
function addToPrefiltersOrTransports( structure ) {

test/unit/ajax.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ test(".ajax() - hash", function() {
492492

493493
test("jQuery ajax - cross-domain detection", function() {
494494

495-
expect( 5 );
495+
expect( 6 );
496496

497497
var loc = document.location,
498498
otherPort = loc.port === 666 ? 667 : 666,
@@ -508,6 +508,7 @@ test("jQuery ajax - cross-domain detection", function() {
508508
});
509509

510510
jQuery.ajax({
511+
dataType: "jsonp",
511512
url: 'app:/path',
512513
beforeSend: function( _ , s ) {
513514
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
@@ -533,6 +534,15 @@ test("jQuery ajax - cross-domain detection", function() {
533534
}
534535
});
535536

537+
jQuery.ajax({
538+
dataType: "jsonp",
539+
url: "about:blank",
540+
beforeSend: function( _ , s ) {
541+
ok( s.crossDomain , "Test about:blank is detected as cross-domain" );
542+
return false;
543+
}
544+
});
545+
536546
jQuery.ajax({
537547
dataType: "jsonp",
538548
url: loc.protocol + "//" + loc.host,

0 commit comments

Comments
 (0)