Skip to content

Commit da3ff3a

Browse files
gibson042dmethvin
authored andcommitted
Fix #12637: restore 1.8.1 ajax crossDomain logic. Close jquerygh-944.
1 parent ebf4d43 commit da3ff3a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/ajax.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,12 @@ jQuery.extend({
580580

581581
// A cross-domain request is in order when we have a protocol:host:port mismatch
582582
if ( s.crossDomain == null ) {
583-
parts = rurl.exec( s.url.toLowerCase() ) || false;
584-
s.crossDomain = parts && ( parts.join(":") + ( parts[ 3 ] ? "" : parts[ 1 ] === "http:" ? 80 : 443 ) ) !==
585-
( ajaxLocParts.join(":") + ( ajaxLocParts[ 3 ] ? "" : ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) );
583+
parts = rurl.exec( s.url.toLowerCase() );
584+
s.crossDomain = !!( parts &&
585+
( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
586+
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
587+
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
588+
);
586589
}
587590

588591
// Convert data if not already a string

test/unit/ajax.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,22 @@ test(".ajax() - hash", function() {
511511

512512
test("jQuery ajax - cross-domain detection", function() {
513513

514-
expect( 6 );
514+
expect( 7 );
515515

516516
var loc = document.location,
517+
samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
517518
otherPort = loc.port === 666 ? 667 : 666,
518519
otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
519520

521+
jQuery.ajax({
522+
dataType: "jsonp",
523+
url: loc.protocol + "//" + loc.host + ":" + samePort,
524+
beforeSend: function( _ , s ) {
525+
ok( !s.crossDomain , "Test matching ports are not detected as cross-domain" );
526+
return false;
527+
}
528+
});
529+
520530
jQuery.ajax({
521531
dataType: "jsonp",
522532
url: otherProtocol + "//" + loc.host,

0 commit comments

Comments
 (0)