// A cross-domain request is in order when we have a protocol:host:port mismatch
if ( s.crossDomain == null ) {
- parts = rurl.exec( s.url.toLowerCase() ) || false;
- s.crossDomain = parts && ( parts.join(":") + ( parts[ 3 ] ? "" : parts[ 1 ] === "http:" ? 80 : 443 ) ) !==
- ( ajaxLocParts.join(":") + ( ajaxLocParts[ 3 ] ? "" : ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) );
+ parts = rurl.exec( s.url.toLowerCase() );
+ s.crossDomain = !!( parts &&
+ ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
+ ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
+ ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
+ );
}
// Convert data if not already a string
test("jQuery ajax - cross-domain detection", function() {
- expect( 6 );
+ expect( 7 );
var loc = document.location,
+ samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
otherPort = loc.port === 666 ? 667 : 666,
otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
+ jQuery.ajax({
+ dataType: "jsonp",
+ url: loc.protocol + "//" + loc.host + ":" + samePort,
+ beforeSend: function( _ , s ) {
+ ok( !s.crossDomain , "Test matching ports are not detected as cross-domain" );
+ return false;
+ }
+ });
+
jQuery.ajax({
dataType: "jsonp",
url: otherProtocol + "//" + loc.host,