Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14773 closed bug (fixed)

load() with selector doesn't work

Reported by: edewata@… Owned by: dmethvin
Priority: high Milestone: 1.11.1/2.1.1
Component: ajax Version: 1.11.0
Keywords: Cc:
Blocked by: Blocking:

Description

Loading a URL that contains a selector doesn't work because there seems to be a parsing error.

For example:

div.load("page.html #content");

The selector should have been just the "#content" but the following jQuery code does not trim the space before the selector, producing " #content".

9981: off = url.indexOf(" ");

9983: if ( off >= 0 ) {
9984:     selector = url.slice( off, url.length );
9985:     url = url.slice( 0, off );
9986: }

When the selector is processed, it doesn't match the following regular expression because of the extra space, so the load() does not produce any result.

724: rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,

797: if ( (match = rquickExpr.exec( selector )) ) {
798:     // Speed-up: Sizzle("#ID")
799:     if ( (m = match[1]) ) {

Change History (5)

comment:1 Changed 9 years ago by dmethvin

Component: unfiledajax
Milestone: None1.11.1
Priority: undecidedhigh
Status: newopen

Yep. I assume this was missed because it worked before we put in xss prevention in 1.8.

comment:2 Changed 9 years ago by deepak.m.shrma

Before: var selector, response, type,

self = this, off = url.indexOf(" ");

if ( off >= 0 ) {

selector = url.slice( off, url.length ); url = url.slice( 0, off );

}

After: var selector, response, type,

self = this, off = url.indexOf(" ");

if ( off >= 0 ) {

selector = url.slice( off+1, url.length ); url = url.slice( 0, off );

}

slice and indexOf both methods work on indexing of the string, where indexing of the string start from 0. Here we didn't considering one extra char which is space. If we leave an extra char space in slice method. It will work fine. var str = "Hello world!"; var res = str.slice(1,5);

it will return "ello".

comment:3 Changed 9 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

comment:4 Changed 9 years ago by dmethvin

Milestone: 1.11.11.11.1/2.1.1

comment:5 Changed 9 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Ajax: .load() should trim its selector

Fixes #14773

Changeset: 3a68c114e3a30af86dc261c9d62ce2ae4144d420

Note: See TracTickets for help on using tickets.