Skip to content

Commit

Permalink
Ajax: .load() should trim its selector
Browse files Browse the repository at this point in the history
Fixes #14773
  • Loading branch information
dmethvin committed Mar 5, 2014
1 parent 10efa1f commit 3a68c11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ajax/load.js
Expand Up @@ -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 );
}

Expand Down
1 change: 1 addition & 0 deletions 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>
8 changes: 8 additions & 0 deletions test/unit/ajax.js
Expand Up @@ -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" );
Expand Down

0 comments on commit 3a68c11

Please sign in to comment.