|
17 | 17 | rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
18 | 18 | rnoContent = /^(?:GET|HEAD)$/,
|
19 | 19 | rprotocol = /^\/\//,
|
20 |
| - rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/, |
21 | 20 |
|
22 | 21 | /* Prefilters
|
23 | 22 | * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
|
|
40 | 39 | // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
41 | 40 | allTypes = "*/".concat( "*" ),
|
42 | 41 |
|
43 |
| - // Document location |
44 |
| - ajaxLocation = location.href, |
45 |
| - |
46 |
| - // Segment location into parts |
47 |
| - ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; |
| 42 | + // Anchor tag for parsing the document origin |
| 43 | + originAnchor = document.createElement( "a" ); |
| 44 | + originAnchor.href = location.href; |
48 | 45 |
|
49 | 46 | // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
|
50 | 47 | function addToPrefiltersOrTransports( structure ) {
|
@@ -288,9 +285,9 @@ jQuery.extend({
|
288 | 285 | etag: {},
|
289 | 286 |
|
290 | 287 | ajaxSettings: {
|
291 |
| - url: ajaxLocation, |
| 288 | + url: location.href, |
292 | 289 | type: "GET",
|
293 |
| - isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ), |
| 290 | + isLocal: rlocalProtocol.test( location.protocol ), |
294 | 291 | global: true,
|
295 | 292 | processData: true,
|
296 | 293 | async: true,
|
@@ -390,8 +387,8 @@ jQuery.extend({
|
390 | 387 | responseHeaders,
|
391 | 388 | // timeout handle
|
392 | 389 | timeoutTimer,
|
393 |
| - // Cross-domain detection vars |
394 |
| - parts, |
| 390 | + // Url cleanup var |
| 391 | + urlAnchor, |
395 | 392 | // To know if global events are to be dispatched
|
396 | 393 | fireGlobals,
|
397 | 394 | // Loop variable
|
@@ -496,23 +493,33 @@ jQuery.extend({
|
496 | 493 | // Add protocol if not provided (prefilters might expect it)
|
497 | 494 | // Handle falsy url in the settings object (#10093: consistency with old signature)
|
498 | 495 | // We also use the url parameter if available
|
499 |
| - s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" ) |
500 |
| - .replace( rprotocol, ajaxLocParts[ 1 ] + "//" ); |
| 496 | + s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" ) |
| 497 | + .replace( rprotocol, location.protocol + "//" ); |
501 | 498 |
|
502 | 499 | // Alias method option to type as per ticket #12004
|
503 | 500 | s.type = options.method || options.type || s.method || s.type;
|
504 | 501 |
|
505 | 502 | // Extract dataTypes list
|
506 | 503 | s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
|
507 | 504 |
|
508 |
| - // A cross-domain request is in order when we have a protocol:host:port mismatch |
| 505 | + // A cross-domain request is in order when the origin doesn't match the current origin. |
509 | 506 | if ( s.crossDomain == null ) {
|
510 |
| - parts = rurl.exec( s.url.toLowerCase() ); |
511 |
| - s.crossDomain = !!( parts && |
512 |
| - ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] || |
513 |
| - ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !== |
514 |
| - ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) ) |
515 |
| - ); |
| 507 | + urlAnchor = document.createElement( "a" ); |
| 508 | + |
| 509 | + // Support: IE8-11+ |
| 510 | + // IE throws exception if url is malformed, e.g. http://example.com:80x/ |
| 511 | + try { |
| 512 | + urlAnchor.href = s.url; |
| 513 | + // Support: IE8-11+ |
| 514 | + // Anchor's host property isn't correctly set when s.url is relative |
| 515 | + urlAnchor.href = urlAnchor.href; |
| 516 | + s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !== |
| 517 | + urlAnchor.protocol + "//" + urlAnchor.host; |
| 518 | + } catch ( e ) { |
| 519 | + // If there is an error parsing the URL, assume it is crossDomain, |
| 520 | + // it can be rejected by the transport if it is invalid |
| 521 | + s.crossDomain = true; |
| 522 | + } |
516 | 523 | }
|
517 | 524 |
|
518 | 525 | // Convert data if not already a string
|
|
0 commit comments