@@ -12,12 +12,11 @@ define([
12
12
var
13
13
rhash = / # .* $ / ,
14
14
rts = / ( [ ? & ] ) _ = [ ^ & ] * / ,
15
- rheaders = / ^ ( .* ?) : [ \t ] * ( [ ^ \r \n ] * ) \r ? $ / mg, // IE leaves an \r character at EOL
15
+ rheaders = / ^ ( .* ?) : [ \t ] * ( [ ^ \r \n ] * ) $ / mg,
16
16
// #7653, #8125, #8152: local protocol detection
17
17
rlocalProtocol = / ^ (?: a b o u t | a p p | a p p - s t o r a g e | .+ - e x t e n s i o n | f i l e | r e s | w i d g e t ) : $ / ,
18
18
rnoContent = / ^ (?: G E T | H E A D ) $ / ,
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 ,
42
+ // Anchor tag for parsing the document origin
43
+ originAnchor = document . createElement ( "a" ) ;
45
44
46
- // Segment location into parts
47
- ajaxLocParts = rurl . exec ( ajaxLocation . toLowerCase ( ) ) || [ ] ;
45
+ originAnchor . href = location . href ;
48
46
49
47
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
50
48
function addToPrefiltersOrTransports ( structure ) {
@@ -287,9 +285,9 @@ jQuery.extend({
287
285
etag : { } ,
288
286
289
287
ajaxSettings : {
290
- url : ajaxLocation ,
288
+ url : location . href ,
291
289
type : "GET" ,
292
- isLocal : rlocalProtocol . test ( ajaxLocParts [ 1 ] ) ,
290
+ isLocal : rlocalProtocol . test ( location . protocol ) ,
293
291
global : true ,
294
292
processData : true ,
295
293
async : true ,
@@ -381,8 +379,7 @@ jQuery.extend({
381
379
// Force options to be an object
382
380
options = options || { } ;
383
381
384
- var // Cross-domain detection vars
385
- parts ,
382
+ var
386
383
// Loop variable
387
384
i ,
388
385
// URL without anti-cache param
@@ -391,7 +388,8 @@ jQuery.extend({
391
388
responseHeadersString ,
392
389
// timeout handle
393
390
timeoutTimer ,
394
-
391
+ // Url cleanup var
392
+ urlAnchor ,
395
393
// To know if global events are to be dispatched
396
394
fireGlobals ,
397
395
@@ -498,24 +496,33 @@ jQuery.extend({
498
496
// Add protocol if not provided (prefilters might expect it)
499
497
// Handle falsy url in the settings object (#10093: consistency with old signature)
500
498
// We also use the url parameter if available
501
- s . url = ( ( url || s . url || ajaxLocation ) + "" )
502
- . replace ( rhash , "" )
503
- . replace ( rprotocol , ajaxLocParts [ 1 ] + "//" ) ;
499
+ s . url = ( ( url || s . url || location . href ) + "" ) . replace ( rhash , "" )
500
+ . replace ( rprotocol , location . protocol + "//" ) ;
504
501
505
502
// Alias method option to type as per ticket #12004
506
503
s . type = options . method || options . type || s . method || s . type ;
507
504
508
505
// Extract dataTypes list
509
506
s . dataTypes = jQuery . trim ( s . dataType || "*" ) . toLowerCase ( ) . match ( rnotwhite ) || [ "" ] ;
510
507
511
- // A cross-domain request is in order when we have a protocol:host:port mismatch
508
+ // A cross-domain request is in order when the origin doesn't match the current origin
512
509
if ( s . crossDomain == null ) {
513
- parts = rurl . exec ( s . url . toLowerCase ( ) ) ;
514
- s . crossDomain = ! ! ( parts &&
515
- ( parts [ 1 ] !== ajaxLocParts [ 1 ] || parts [ 2 ] !== ajaxLocParts [ 2 ] ||
516
- ( parts [ 3 ] || ( parts [ 1 ] === "http:" ? "80" : "443" ) ) !==
517
- ( ajaxLocParts [ 3 ] || ( ajaxLocParts [ 1 ] === "http:" ? "80" : "443" ) ) )
518
- ) ;
510
+ urlAnchor = document . createElement ( "a" ) ;
511
+
512
+ // Support: IE8-11+
513
+ // IE throws exception if url is malformed, e.g. http://example.com:80x/
514
+ try {
515
+ urlAnchor . href = s . url ;
516
+ // Support: IE8-11+
517
+ // Anchor's host property isn't correctly set when s.url is relative
518
+ urlAnchor . href = urlAnchor . href ;
519
+ s . crossDomain = originAnchor . protocol + "//" + originAnchor . host !==
520
+ urlAnchor . protocol + "//" + urlAnchor . host ;
521
+ } catch ( e ) {
522
+ // If there is an error parsing the URL, assume it is crossDomain,
523
+ // it can be rejected by the transport if it is invalid
524
+ s . crossDomain = true ;
525
+ }
519
526
}
520
527
521
528
// Convert data if not already a string
0 commit comments