New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad URLs with hashes are not gracefully handled #4119

Closed
jefflembeck opened this Issue Apr 19, 2012 · 5 comments

Comments

Projects
None yet
7 participants
@jefflembeck
Contributor

jefflembeck commented Apr 19, 2012

I'm not sure if this is by design or not, but

http://jquerymobile.com/demos/1.1.0/##

Is a decent example of this.

I'd expect the page to just load at this point, instead it freezes with a JS error. This is likely caused by the way that hash changes are handled.

@toddparker

This comment has been minimized.

Show comment
Hide comment
@toddparker

toddparker Apr 20, 2012

Contributor

Yeah, this is a bug for sure. In fact, an empty hash should probably be ignored too (/#), right now it navigate you to the root.

Contributor

toddparker commented Apr 20, 2012

Yeah, this is a bug for sure. In fact, an empty hash should probably be ignored too (/#), right now it navigate you to the root.

@ghost ghost assigned johnbender Apr 20, 2012

@barneycarroll

This comment has been minimized.

Show comment
Hide comment
@barneycarroll

barneycarroll Apr 20, 2012

Double hash, or any form of bad URL, is not necessary — any (legitimate) hash will break init, eg:

http://jquerymobile.com/demos/1.1.0/#jqm-logo

From my execution, no errors are thrown, and no custom events are fired — the page rests in a loading state and initialisation is frozen.

EDIT: You can prevent this behaviour by executing jQuery.mobile.hashListeningEnabled = false; before DOM ready. But you shouldn't have to chose between a staple of native web behaviour & jQM history management.

Double hash, or any form of bad URL, is not necessary — any (legitimate) hash will break init, eg:

http://jquerymobile.com/demos/1.1.0/#jqm-logo

From my execution, no errors are thrown, and no custom events are fired — the page rests in a loading state and initialisation is frozen.

EDIT: You can prevent this behaviour by executing jQuery.mobile.hashListeningEnabled = false; before DOM ready. But you shouldn't have to chose between a staple of native web behaviour & jQM history management.

@frequent

This comment has been minimized.

Show comment
Hide comment
@frequent

frequent Apr 20, 2012

Contributor

I'm also running across this when trying to load deeplinks using my multiview plugin, because by default my some.html#nested_page_ID will also be a bad URL. I have patched my JQM like this to fix it for me:

 // also check for panel subpages
 if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) || $( window.location.hash ).closest('div:jqmData(role="panel")').length > 0 ) {              
            // store hash, retrieve inside multiview
            $('html').data("deep", window.location.hash);
            // back to JQM
            $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
        }

I'm trying to get by without touching JQM.js, so in case you are adding some more logic and are open for wishes... I would also like a custom event such as "loadFirstPage" to tap into.

I guess once you start thinking about supporting anchor tags, you will need some more logic here anyway, because all anchor tags will be bad as of now. What do you think?

Contributor

frequent commented Apr 20, 2012

I'm also running across this when trying to load deeplinks using my multiview plugin, because by default my some.html#nested_page_ID will also be a bad URL. I have patched my JQM like this to fix it for me:

 // also check for panel subpages
 if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) || $( window.location.hash ).closest('div:jqmData(role="panel")').length > 0 ) {              
            // store hash, retrieve inside multiview
            $('html').data("deep", window.location.hash);
            // back to JQM
            $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
        }

I'm trying to get by without touching JQM.js, so in case you are adding some more logic and are open for wishes... I would also like a custom event such as "loadFirstPage" to tap into.

I guess once you start thinking about supporting anchor tags, you will need some more logic here anyway, because all anchor tags will be bad as of now. What do you think?

@ghost ghost assigned gseguin Apr 26, 2012

@frequent

This comment has been minimized.

Show comment
Hide comment
@frequent

frequent May 4, 2012

Contributor

@gseguin

Thinking more about a loadFirstPage event.... this would also be very useful for deeplinks to artifical hashtags. Say I have a page some.html, in which I'm updating content via Ajax.

I would like to reflect the updated page by changing the hashtag, but I can't because all deeplinks to this page ala some.html#new_content will break, because the page isn't there and I'm missing an event to tap into the first page being loaded to redirect to the actual page and fire an Ajax call to update the content.

No problem on the 2nd page with pagebeforechange, but on the first page, this does not fire, does it?

If I could do:

$(document).on('firstpageload', ':jqmData(role="page")', function(e, data) {
    if ( if the deeplink requested is NOT in the document ) {
        e.preventDefault();
        // do something else
        } 
    })
Contributor

frequent commented May 4, 2012

@gseguin

Thinking more about a loadFirstPage event.... this would also be very useful for deeplinks to artifical hashtags. Say I have a page some.html, in which I'm updating content via Ajax.

I would like to reflect the updated page by changing the hashtag, but I can't because all deeplinks to this page ala some.html#new_content will break, because the page isn't there and I'm missing an event to tap into the first page being loaded to redirect to the actual page and fire an Ajax call to update the content.

No problem on the 2nd page with pagebeforechange, but on the first page, this does not fire, does it?

If I could do:

$(document).on('firstpageload', ':jqmData(role="page")', function(e, data) {
    if ( if the deeplink requested is NOT in the document ) {
        e.preventDefault();
        // do something else
        } 
    })
@jefflembeck

This comment has been minimized.

Show comment
Hide comment
@jefflembeck

jefflembeck May 25, 2012

Contributor

Just to note, based on this proposed fix: when hash listening is enabled, things still break.

Contributor

jefflembeck commented May 25, 2012

Just to note, based on this proposed fix: when hash listening is enabled, things still break.

hpbuniat pushed a commit to hpbuniat/jquery-mobile that referenced this issue May 26, 2012

Merge pull request #4455 from jasondscott/4119_BadHash
Fixes #4119 - Bad URLs with hashes are not gracefully handled

jasondscott pushed a commit that referenced this issue May 29, 2012

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.

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