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

Fixes #4119 - Bad URLs with hashes are not gracefully handled #4455

Merged
merged 2 commits into from
May 26, 2012

Conversation

jasondscott
Copy link
Contributor

Fixes issue #4119
Added regex test to see if hash is valid and if a page with that id
exists, if not load the first page.

…andled

Fixes issue jquery-archive#4119
Added regex test to see if hash is valid and if a page with that id
exists, if not load the first page.
// if hashchange listening is disabled, there's no hash deeplink,
// the hash is not valid (contains more than one # or does not start with #)
// or there is no page with that hash, change to the first page in the DOM
if ( !$.mobile.hashListeningEnabled || /(^#$)|(#.*#.*)|(^[^#].+)/.test( location.hash ) || !$( location.hash + ':jqmData(role="page")' ).length ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would push this into the $.mobile.path object at the top of jquery.mobile.navigation.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like $.mobile.path.isHashValid( location.hash )?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jefflembeck
Copy link
Contributor

In the original bug, hash listening is enabled and it's still breaking. There's something deeper to this, I think.

@jasondscott
Copy link
Contributor Author

@jlembeck With this change, if hash listening is enabled and the hash is not valid the first page will be loaded. If hash listening is disabled then the first page will be loaded.

Added unit tests for isHashValid
@jefflembeck
Copy link
Contributor

@jasondscott gotcha. Read my results incorrectly when trying it out on my URL.

jasondscott added a commit that referenced this pull request May 26, 2012
Fixes #4119 - Bad URLs with hashes are not gracefully handled
@jasondscott jasondscott merged commit c8c4cde into jquery-archive:master May 26, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants