Permalink
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 2c83dff commit ca94e5fc7ae5f6c26e3cd7ee4d76dbf9899160f8 @johnbender johnbender committed Aug 15, 2012
@@ -674,8 +674,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
@@ -689,7 +689,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
@@ -858,7 +860,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
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+ <div data-nstest-role="page">
+ Parens!
+ </div>
+</body>
+</html>
@@ -1244,4 +1244,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 ca94e5f

Please sign in to comment.