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

Merged
merged 2 commits into from May 26, 2012

Conversation

Projects
None yet
3 participants
Contributor

jasondscott commented May 25, 2012

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.

Jason Scott Fixes #4119 - Bad URLs with hashes are not gracefully handled
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.
fb0a766

@johnbender johnbender and 1 other commented on an outdated diff May 25, 2012

js/jquery.mobile.init.js
@@ -77,8 +77,10 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.support", "./jquery
//remove initial build class (only present on first pageshow)
hideRenderingClass();
- // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
- if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ) {
+ // 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 ) {
@johnbender

johnbender May 25, 2012

Contributor

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

@jasondscott

jasondscott May 25, 2012

Contributor

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

@johnbender

johnbender May 26, 2012

Contributor

👍

Contributor

jefflembeck commented May 25, 2012

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

Contributor

jasondscott commented May 25, 2012

@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.

Jason Scott Moved hash validation into $.mobile.path.isHashValid
Added unit tests for isHashValid
15f404e
Contributor

jefflembeck commented May 26, 2012

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

jasondscott merged commit c8c4cde into jquery:master May 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment