Opened 9 years ago
Closed 9 years ago
#14773 closed bug (fixed)
load() with selector doesn't work
Reported by: | 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
Component: | unfiled → ajax |
---|---|
Milestone: | None → 1.11.1 |
Priority: | undecided → high |
Status: | new → open |
comment:2 Changed 9 years ago by
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
Owner: | set to dmethvin |
---|---|
Status: | open → assigned |
comment:4 Changed 9 years ago by
Milestone: | 1.11.1 → 1.11.1/2.1.1 |
---|
comment:5 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Ajax: .load() should trim its selector
Fixes #14773
Changeset: 3a68c114e3a30af86dc261c9d62ce2ae4144d420
Yep. I assume this was missed because it worked before we put in xss prevention in 1.8.