Skip to content

Commit 3a68c11

Browse files
committed
Ajax: .load() should trim its selector
Fixes #14773
1 parent 10efa1f commit 3a68c11

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/ajax/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jQuery.fn.load = function( url, params, callback ) {
2525
off = url.indexOf(" ");
2626

2727
if ( off >= 0 ) {
28-
selector = url.slice( off );
28+
selector = jQuery.trim( url.slice( off ) );
2929
url = url.slice( 0, off );
3030
}
3131

test/data/test3.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div class="user">This is a user</div>
22
<div class="user">This is a user</div>
33
<div class="teacher">This is a teacher</div>
4+
<div id="superuser">This is a superuser</div>

test/unit/ajax.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,14 @@ module( "ajax", {
18071807
});
18081808
});
18091809

1810+
// Selector should be trimmed to avoid leading spaces (#14773)
1811+
asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() {
1812+
jQuery("#first").load( "data/test3.html #superuser ", function() {
1813+
strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" );
1814+
start();
1815+
});
1816+
});
1817+
18101818
asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
18111819
jQuery("#first").load( url("data/name.html"), function() {
18121820
ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );

0 commit comments

Comments
 (0)