Bug Tracker

Ticket #14773 (closed bug: fixed)

Opened 7 months ago

Last modified 7 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 7 months ago by dmethvin

  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to ajax
  • Milestone changed from None to 1.11.1

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

comment:2 Changed 7 months 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 7 months ago by dmethvin

  • Owner set to dmethvin
  • Status changed from open to assigned

comment:4 Changed 7 months ago by dmethvin

  • Milestone changed from 1.11.1 to 1.11.1/2.1.1

comment:5 Changed 7 months ago by Dave Methvin

  • Status changed from assigned to closed
  • Resolution set to fixed

Ajax: .load() should trim its selector

Fixes #14773

Changeset: 3a68c114e3a30af86dc261c9d62ce2ae4144d420

Note: See TracTickets for help on using tickets.