Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Correctly store data-url and correctly select for it #7474

Closed
wants to merge 17 commits into from

Conversation

gabrielschulhof
Copy link

This also removes any lingering references to subPageUrlKey from the code.

Fixes gh-1383

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) when pulling b29e5bf on 1383-escape-urls-in-data-url-selector into 1ed6f92 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.17%) when pulling 3899174 on 1383-escape-urls-in-data-url-selector into 1ed6f92 on master.

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 ) + "']" );
Copy link

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?

Copy link
Author

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.

Copy link

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.

Copy link
Author

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.12%) when pulling 5769c0c on 1383-escape-urls-in-data-url-selector into 1ed6f92 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) when pulling 047db48 on 1383-escape-urls-in-data-url-selector into 2f7d1c6 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) when pulling 047db48 on 1383-escape-urls-in-data-url-selector into 2f7d1c6 on master.

@dpolivy
Copy link

dpolivy commented Jun 9, 2014

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.

@gabrielschulhof
Copy link
Author

@dpolivy Excellent!

@dpolivy
Copy link

dpolivy commented Jun 11, 2014

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 $.mobile.path.convertUrlToDataUrl with throw a URIError: URI Malformed exception. Before, this just seemed to work OK (even though the URL was "invalid").

To repro: navigate to a URL with a string like the following in it: Domaine+du+P%E9ga%FC.

Thoughts on the best way to handle this?

@arschmitz
Copy link
Contributor

I think this looks good however some of the names of the new files contain spaces can you fix this please.

@dpolivy
Copy link

dpolivy commented Aug 21, 2014

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.

@arschmitz
Copy link
Contributor

@dpolivy thanks ill take a look at your comment

@gabrielschulhof gabrielschulhof force-pushed the 1383-escape-urls-in-data-url-selector branch 2 times, most recently from 13290a4 to c3b1939 Compare August 23, 2014 16:06
@gabrielschulhof gabrielschulhof force-pushed the 1383-escape-urls-in-data-url-selector branch 2 times, most recently from 79abe6f to 963c021 Compare August 26, 2014 06:33
@gabrielschulhof gabrielschulhof force-pushed the 1383-escape-urls-in-data-url-selector branch from 963c021 to 4483140 Compare August 26, 2014 06:34
@gabrielschulhof
Copy link
Author

I believe I've addressed @dpolivy's comment.

@arschmitz
Copy link
Contributor

You still have file names containing spaces please fix these.

@arschmitz
Copy link
Contributor

👍

@gabrielschulhof gabrielschulhof deleted the 1383-escape-urls-in-data-url-selector branch September 4, 2014 18:22
gabrielschulhof pushed a commit that referenced this pull request Sep 4, 2014
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
agcolom pushed a commit to agcolom/jquery-mobile that referenced this pull request Nov 26, 2014
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

changePage breaks when data hash contains parentheses/apostropes
5 participants