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

Commit

Permalink
Fixes #4119 - Bad URLs with hashes are not gracefully handled
Browse files Browse the repository at this point in the history
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
Jason Scott committed May 25, 2012
1 parent 81cc987 commit fb0a766
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions js/jquery.mobile.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb0a766

Please sign in to comment.