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

Commit ca94e5f

Browse files
committed
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
1 parent 2c83dff commit ca94e5f

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

js/jquery.mobile.navigation.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ define( [
674674
settings.reloadPage = true;
675675
}
676676

677-
// The absolute version of the URL minus any dialog/subpage params.
678-
// In otherwords the real URL of the page to be loaded.
677+
// The absolute version of the URL minus any dialog/subpage params.
678+
// In otherwords the real URL of the page to be loaded.
679679
var fileUrl = path.getFilePath( absUrl ),
680680

681681
// The version of the Url actually stored in the data-url attribute of
@@ -689,7 +689,9 @@ define( [
689689
settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
690690

691691
// Check to see if the page already exists in the DOM.
692-
page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
692+
// NOTE do _not_ use the :jqmData psuedo selector because parenthesis
693+
// are a valid url char and it breaks on the first occurence
694+
page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" );
693695

694696
// If we failed to find the page, check to see if the url is a
695697
// reference to an embedded page. If so, it may have been dynamically
@@ -858,7 +860,7 @@ define( [
858860
// into the DOM. If the original absUrl refers to a sub-page, that is the
859861
// real page we are interested in.
860862
if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) {
861-
page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
863+
page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" );
862864
}
863865

864866
//bind pageHide to removePage after it's hidden, if the page options specify to do so
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
</head>
5+
<body>
6+
<div data-nstest-role="page">
7+
Parens!
8+
</div>
9+
</body>
10+
</html>

tests/unit/navigation/navigation_core.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,4 +1244,25 @@
12441244
}
12451245
]);
12461246
});
1247+
1248+
asyncTest( "test that data-urls with parens work properly (avoid jqmData regex)", function() {
1249+
$.testHelper.pageSequence([
1250+
function() {
1251+
$.mobile.changePage( "data-url-tests/parentheses.html?foo=(bar)" );
1252+
},
1253+
1254+
function() {
1255+
window.history.back();
1256+
},
1257+
1258+
function() {
1259+
window.history.forward();
1260+
},
1261+
1262+
function() {
1263+
equal( $.trim($.mobile.activePage.text()), "Parens!", "the page loaded" );
1264+
start();
1265+
}
1266+
]);
1267+
});
12471268
})(jQuery);

0 commit comments

Comments
 (0)