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

Commit

Permalink
Handle urls with parens properly
Browse files Browse the repository at this point in the history
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
johnbender committed Aug 15, 2012
1 parent 5572b5e commit cb15dc3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js/jquery.mobile.navigation.js
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions 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>
21 changes: 21 additions & 0 deletions tests/unit/navigation/navigation_core.js
Expand Up @@ -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.