Fixes #5856. Adds document protocol at the beginning of URLs without protocol (thanks go to skrings for the initial pull request). Simplifies cross-domain detection regexp and logic as a consequence. Also took the opportunity to remove an unused variable. Unit test added.
This commit is contained in:
parent
325dcdc2ab
commit
0e5b341cc0
2 changed files with 20 additions and 11 deletions
17
src/ajax.js
17
src/ajax.js
|
@ -7,15 +7,13 @@ var r20 = /%20/g,
|
||||||
rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL
|
rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL
|
||||||
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
||||||
rnoContent = /^(?:GET|HEAD)$/,
|
rnoContent = /^(?:GET|HEAD)$/,
|
||||||
|
rprotocol = /^\/\//,
|
||||||
rquery = /\?/,
|
rquery = /\?/,
|
||||||
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
||||||
rselectTextarea = /^(?:select|textarea)/i,
|
rselectTextarea = /^(?:select|textarea)/i,
|
||||||
rspacesAjax = /\s+/,
|
rspacesAjax = /\s+/,
|
||||||
rts = /([?&])_=[^&]*/,
|
rts = /([?&])_=[^&]*/,
|
||||||
rurl = /^(\w+:)?\/\/([^\/?#:]+)(?::(\d+))?/,
|
rurl = /^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/,
|
||||||
|
|
||||||
// Slice function
|
|
||||||
sliceFunc = Array.prototype.slice,
|
|
||||||
|
|
||||||
// Keep a copy of the old load method
|
// Keep a copy of the old load method
|
||||||
_load = jQuery.fn.load,
|
_load = jQuery.fn.load,
|
||||||
|
@ -544,8 +542,9 @@ jQuery.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove hash character (#7531: and string promotion)
|
// Remove hash character (#7531: and string promotion)
|
||||||
|
// Add protocol if not provided (#5856: IE7 issue with protocol-less urls)
|
||||||
// We also use the url parameter if available
|
// We also use the url parameter if available
|
||||||
s.url = ( "" + ( url || s.url ) ).replace( rhash, "" );
|
s.url = ( "" + ( url || s.url ) ).replace( rhash, "" ).replace( rprotocol, protocol + "//" );
|
||||||
|
|
||||||
// Extract dataTypes list
|
// Extract dataTypes list
|
||||||
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
|
||||||
|
@ -553,11 +552,9 @@ jQuery.extend({
|
||||||
// Determine if a cross-domain request is in order
|
// Determine if a cross-domain request is in order
|
||||||
if ( !s.crossDomain ) {
|
if ( !s.crossDomain ) {
|
||||||
parts = rurl.exec( s.url.toLowerCase() );
|
parts = rurl.exec( s.url.toLowerCase() );
|
||||||
s.crossDomain = !!(
|
s.crossDomain = !!( parts &&
|
||||||
parts &&
|
( parts[ 1 ] != protocol || parts[ 2 ] != loc.hostname ||
|
||||||
( parts[ 1 ] && parts[ 1 ] != protocol ||
|
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
|
||||||
parts[ 2 ] != loc.hostname ||
|
|
||||||
( parts[ 3 ] || ( ( parts[ 1 ] || protocol ) === "http:" ? 80 : 443 ) ) !=
|
|
||||||
( loc.port || ( protocol === "http:" ? 80 : 443 ) ) )
|
( loc.port || ( protocol === "http:" ? 80 : 443 ) ) )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,6 +415,18 @@ test(".ajax() - contentType" , function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(".ajax() - protocol-less urls", function() {
|
||||||
|
expect(1);
|
||||||
|
|
||||||
|
jQuery.ajax({
|
||||||
|
url: "//somedomain.com",
|
||||||
|
beforeSend: function( xhr, settings ) {
|
||||||
|
equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test(".ajax() - hash", function() {
|
test(".ajax() - hash", function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue