aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2014-03-03 21:37:56 -0500
committerDave Methvin <dave.methvin@gmail.com>2014-03-04 20:43:14 -0500
commit3a68c114e3a30af86dc261c9d62ce2ae4144d420 (patch)
tree7396bae6fbd77baf49c89676947d585650490567
parent10efa1f5b44046aab6bcc8423322a41923faa290 (diff)
downloadjquery-3a68c114e3a30af86dc261c9d62ce2ae4144d420.tar.gz
jquery-3a68c114e3a30af86dc261c9d62ce2ae4144d420.zip
Ajax: .load() should trim its selector
Fixes #14773
-rw-r--r--src/ajax/load.js2
-rw-r--r--test/data/test3.html1
-rw-r--r--test/unit/ajax.js8
3 files changed, 10 insertions, 1 deletions
diff --git a/src/ajax/load.js b/src/ajax/load.js
index 3c345a027..bff25b1a4 100644
--- a/src/ajax/load.js
+++ b/src/ajax/load.js
@@ -25,7 +25,7 @@ jQuery.fn.load = function( url, params, callback ) {
off = url.indexOf(" ");
if ( off >= 0 ) {
- selector = url.slice( off );
+ selector = jQuery.trim( url.slice( off ) );
url = url.slice( 0, off );
}
diff --git a/test/data/test3.html b/test/data/test3.html
index 909d41745..a7f862a86 100644
--- a/test/data/test3.html
+++ b/test/data/test3.html
@@ -1,3 +1,4 @@
<div class="user">This is a user</div>
<div class="user">This is a user</div>
<div class="teacher">This is a teacher</div>
+<div id="superuser">This is a superuser</div>
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index c7d7daba4..a07749fc6 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1807,6 +1807,14 @@ module( "ajax", {
});
});
+ // Selector should be trimmed to avoid leading spaces (#14773)
+ asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() {
+ jQuery("#first").load( "data/test3.html #superuser ", function() {
+ strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" );
+ start();
+ });
+ });
+
asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
jQuery("#first").load( url("data/name.html"), function() {
ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );