Permalink
Browse files

Fix #12637: restore 1.8.1 ajax crossDomain logic. Close gh-944.

  • Loading branch information...
1 parent ebf4d43 commit da3ff3afe4d8421ae4ad04d6653f04ed6d7768e3 @gibson042 gibson042 committed with dmethvin Oct 3, 2012
Showing with 17 additions and 4 deletions.
  1. +6 −3 src/ajax.js
  2. +11 −1 test/unit/ajax.js
View
@@ -580,9 +580,12 @@ jQuery.extend({
// 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
View
@@ -511,14 +511,24 @@ test(".ajax() - hash", function() {
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,
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test different protocols are detected as cross-domain" );

0 comments on commit da3ff3a

Please sign in to comment.