-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Correctly store data-url and correctly select for it #7474
Conversation
page, initialContent = this._getInitialContent(); | ||
|
||
// Check to see if the page already exists in the DOM. | ||
// NOTE do _not_ use the :jqmData pseudo selector because parenthesis | ||
// are a valid url char and it breaks on the first occurence | ||
page = this.element | ||
.children( "[data-" + this._getNs() +"url='" + dataUrl + "']" ); | ||
.children( "[data-" + this._getNs() + | ||
"url='" + $.mobile.path.hashToSelector( dataUrl ) + "']" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use decodedDataUrl too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because we stipulate that dataUrl must not contain a a uri-encoded string. So, when we retrieve the attribute value, we should be able to assume that it's not encoded. If it is, it's not our fault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is created from the passed in absUrl, not the data attribute -- i.e. this is the page we are navigating TO. So this is the first check to see if it is in the DOM.
In my form submission scenario, absUrl contains the serialized form parameters, which includes the encoded characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now modified convertUrlToDataUrl() to always decode. This fixes your concern here, and it also addresses the potential double-decoding problem.
1 similar comment
Took a quick look at the code and I think the current set of changes address all of the known issues I've found. Nice work, and thanks! Will try to incorporate the changes into my local build and do additional testing. |
@dpolivy Excellent! |
After using this a bit more, I am seeing one change in behavior from before: if one attempts to navigate to a URL which has non-UTF8 encoded characters (e.g. from escape()), then the new To repro: navigate to a URL with a string like the following in it: Thoughts on the best way to handle this? |
I think this looks good however some of the names of the new files contain spaces can you fix this please. |
Can you also review my comment on the associated issue (#1383 (comment)) -- I think there's a small corner case that needs attention to fully fix this. |
@dpolivy thanks ill take a look at your comment |
13290a4
to
c3b1939
Compare
79abe6f
to
963c021
Compare
This also removes the possibility that a URL gets double-decoded.
963c021
to
4483140
Compare
I believe I've addressed @dpolivy's comment. |
You still have file names containing spaces please fix these. |
👍 |
Also removes code dealing with nested list URL tokens (subPageUrlKey) The initial bug was regarding the need to use selector-escaping when looking for pages inside the DOM via their data-url attribute, because the the data-url may contain "weird" characters like parantheses, single, and double quotes. During the process of fixing this it became clear that the data-url attribute can sometimes end up having a URL-encoded value - but not always. This makes proper string comparison, much less selector-escaping, impossible. So, it became necessary to require that data-url never be url-encoded. Conversely, the URL that ends up in the location when using replaceState() must be URL-encoded, otherwise, upon deep linking, one may end up with an invalid URL. For example, if the URL contains an actual percent sign, and the URL is placed in the location via replaceState(), the percent sign must be URL-encoded in order for deep-linking to work. Below are the original commit messages that have been squashed: Pagecontainer: Escape dataUrl when trying to find page based on it Navigation: Make sure location is encoded when going to a funky page Pagecontainer: Test that _find() throws not when looking for weird URLs Init: Correctly assign data-url for initial page Init: Make sure "data-url" attribute for initial page is decoded Pagecontainer: Decode URI when assigning to "data-url" during _parse() Pagecontainer: Use decoded URL to build selector for data-url Pagecontainer: Call convertUrlToDataUrl() via _createDataUrl() Path: Always uri-decode when computing dataUrl Pagecontainer: Remove extra decoding step, now part of _createDataUrl() This also removes the possibility that a URL gets double-decoded. Pagecontainer: Test behavior of _find() in the face of weird URLs Navigation: Use data-url retrieved from Ajax request in its encoded form Pagecontainer: Pass encoded URL to $.mobile.navigate() Init: Rename JS file with spaces in it (cherry picked from commit e412102) Closes gh-7474 Fixes gh-1383
Also removes code dealing with nested list URL tokens (subPageUrlKey) The initial bug was regarding the need to use selector-escaping when looking for pages inside the DOM via their data-url attribute, because the the data-url may contain "weird" characters like parantheses, single, and double quotes. During the process of fixing this it became clear that the data-url attribute can sometimes end up having a URL-encoded value - but not always. This makes proper string comparison, much less selector-escaping, impossible. So, it became necessary to require that data-url never be url-encoded. Conversely, the URL that ends up in the location when using replaceState() must be URL-encoded, otherwise, upon deep linking, one may end up with an invalid URL. For example, if the URL contains an actual percent sign, and the URL is placed in the location via replaceState(), the percent sign must be URL-encoded in order for deep-linking to work. Below are the original commit messages that have been squashed: Pagecontainer: Escape dataUrl when trying to find page based on it Navigation: Make sure location is encoded when going to a funky page Pagecontainer: Test that _find() throws not when looking for weird URLs Init: Correctly assign data-url for initial page Init: Make sure "data-url" attribute for initial page is decoded Pagecontainer: Decode URI when assigning to "data-url" during _parse() Pagecontainer: Use decoded URL to build selector for data-url Pagecontainer: Call convertUrlToDataUrl() via _createDataUrl() Path: Always uri-decode when computing dataUrl Pagecontainer: Remove extra decoding step, now part of _createDataUrl() This also removes the possibility that a URL gets double-decoded. Pagecontainer: Test behavior of _find() in the face of weird URLs Navigation: Use data-url retrieved from Ajax request in its encoded form Pagecontainer: Pass encoded URL to $.mobile.navigate() Init: Rename JS file with spaces in it Closes jquery-archivegh-7474 Fixes jquery-archivegh-1383
This also removes any lingering references to
subPageUrlKey
from the code.Fixes gh-1383