Browse files

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
  • Loading branch information...
1 parent 5572b5e commit cb15dc3b13622e5776e5e5914213bc3d974180ce @johnbender johnbender committed Aug 15, 2012
View
10 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
View
10 tests/unit/navigation/data-url-tests/parentheses.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+ <div data-nstest-role="page">
+ Parens!
+ </div>
+</body>
+</html>
View
21 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);

0 comments on commit cb15dc3

Please sign in to comment.