From cb15dc3b13622e5776e5e5914213bc3d974180ce Mon Sep 17 00:00:00 2001 From: John Bender Date: Wed, 15 Aug 2012 11:09:41 -0700 Subject: [PATCH] Handle urls with parens properly The regular expression used to parse the jqmData psuedo selector restricts the use of parentheses which are valid in urls. This breaks data-ns-url selection. The fix is to avoid the pseudo selector. Fixes #4849 --- js/jquery.mobile.navigation.js | 10 +++++---- .../data-url-tests/parentheses.html | 10 +++++++++ tests/unit/navigation/navigation_core.js | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tests/unit/navigation/data-url-tests/parentheses.html diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 16579dbc42c..a5b88c5c7cb 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -676,8 +676,8 @@ define( [ settings.reloadPage = true; } - // The absolute version of the URL minus any dialog/subpage params. - // In otherwords the real URL of the page to be loaded. + // The absolute version of the URL minus any dialog/subpage params. + // In otherwords the real URL of the page to be loaded. var fileUrl = path.getFilePath( absUrl ), // The version of the Url actually stored in the data-url attribute of @@ -691,7 +691,9 @@ define( [ settings.pageContainer = settings.pageContainer || $.mobile.pageContainer; // Check to see if the page already exists in the DOM. - page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" ); + // NOTE do _not_ use the :jqmData psuedo selector because parenthesis + // are a valid url char and it breaks on the first occurence + page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" ); // If we failed to find the page, check to see if the url is a // reference to an embedded page. If so, it may have been dynamically @@ -861,7 +863,7 @@ define( [ // into the DOM. If the original absUrl refers to a sub-page, that is the // real page we are interested in. if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) { - page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" ); + page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" ); } //bind pageHide to removePage after it's hidden, if the page options specify to do so diff --git a/tests/unit/navigation/data-url-tests/parentheses.html b/tests/unit/navigation/data-url-tests/parentheses.html new file mode 100644 index 00000000000..2efc49a2343 --- /dev/null +++ b/tests/unit/navigation/data-url-tests/parentheses.html @@ -0,0 +1,10 @@ + + + + + +
+ Parens! +
+ + diff --git a/tests/unit/navigation/navigation_core.js b/tests/unit/navigation/navigation_core.js index d401eee5deb..f63e3bd9aba 100644 --- a/tests/unit/navigation/navigation_core.js +++ b/tests/unit/navigation/navigation_core.js @@ -1225,4 +1225,25 @@ } ]); }); + + asyncTest( "test that data-urls with parens work properly (avoid jqmData regex)", function() { + $.testHelper.pageSequence([ + function() { + $.mobile.changePage( "data-url-tests/parentheses.html?foo=(bar)" ); + }, + + function() { + window.history.back(); + }, + + function() { + window.history.forward(); + }, + + function() { + equal( $.trim($.mobile.activePage.text()), "Parens!", "the page loaded" ); + start(); + } + ]); + }); })(jQuery);