Permalink
Browse files

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.
  • Loading branch information...
1 parent 81cc987 commit fb0a7660dcc7c1c9d46e671bc01bff7964e38b9d Jason Scott committed May 25, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 js/jquery.mobile.init.js
View
6 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 ) {
$.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
}
// otherwise, trigger a hashchange to load a deeplink

0 comments on commit fb0a766

Please sign in to comment.