Skip to main content

Bug Tracker

Side navigation

#14773 closed bug (fixed)

Opened February 07, 2014 11:20PM UTC

Closed March 05, 2014 02:50AM UTC

load() with selector doesn't work

Reported by: edewata@redhat.com 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]) ) {
Attachments (0)
Change History (5)

Changed February 18, 2014 11:01PM UTC by dmethvin comment:1

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.

Changed February 24, 2014 04:57AM UTC by deepak.m.shrma comment:2

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".

Changed March 04, 2014 02:38AM UTC by dmethvin comment:3

owner: → dmethvin
status: openassigned

Changed March 04, 2014 02:42PM UTC by dmethvin comment:4

milestone: 1.11.11.11.1/2.1.1

Changed March 05, 2014 02:50AM UTC by Dave Methvin comment:5

resolution: → fixed
status: assignedclosed

Ajax: .load() should trim its selector

Fixes #14773

Changeset: 3a68c114e3a30af86dc261c9d62ce2ae4144d420