Skip to content
This repository
Browse code

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...
commit cb15dc3b13622e5776e5e5914213bc3d974180ce 1 parent 5572b5e
John Bender authored August 15, 2012
10  js/jquery.mobile.navigation.js
@@ -676,8 +676,8 @@ define( [
676 676
 			settings.reloadPage = true;
677 677
 		}
678 678
 
679  
-			// The absolute version of the URL minus any dialog/subpage params.
680  
-			// In otherwords the real URL of the page to be loaded.
  679
+		// The absolute version of the URL minus any dialog/subpage params.
  680
+		// In otherwords the real URL of the page to be loaded.
681 681
 		var fileUrl = path.getFilePath( absUrl ),
682 682
 
683 683
 			// The version of the Url actually stored in the data-url attribute of
@@ -691,7 +691,9 @@ define( [
691 691
 		settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
692 692
 
693 693
 		// Check to see if the page already exists in the DOM.
694  
-		page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
  694
+		// NOTE do _not_ use the :jqmData psuedo selector because parenthesis
  695
+		//      are a valid url char and it breaks on the first occurence
  696
+		page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" );
695 697
 
696 698
 		// If we failed to find the page, check to see if the url is a
697 699
 		// reference to an embedded page. If so, it may have been dynamically
@@ -861,7 +863,7 @@ define( [
861 863
 					// into the DOM. If the original absUrl refers to a sub-page, that is the
862 864
 					// real page we are interested in.
863 865
 					if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) {
864  
-						page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
  866
+						page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" );
865 867
 					}
866 868
 
867 869
 					//bind pageHide to removePage after it's hidden, if the page options specify to do so
10  tests/unit/navigation/data-url-tests/parentheses.html
... ...
@@ -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>
21  tests/unit/navigation/navigation_core.js
@@ -1225,4 +1225,25 @@
1225 1225
 			}
1226 1226
 		]);
1227 1227
 	});
  1228
+
  1229
+	asyncTest( "test that data-urls with parens work properly (avoid jqmData regex)", function() {
  1230
+		$.testHelper.pageSequence([
  1231
+			function() {
  1232
+				$.mobile.changePage( "data-url-tests/parentheses.html?foo=(bar)" );
  1233
+			},
  1234
+
  1235
+			function() {
  1236
+				window.history.back();
  1237
+			},
  1238
+
  1239
+			function() {
  1240
+				window.history.forward();
  1241
+			},
  1242
+
  1243
+			function() {
  1244
+				equal( $.trim($.mobile.activePage.text()), "Parens!", "the page loaded" );
  1245
+				start();
  1246
+			}
  1247
+		]);
  1248
+	});
1228 1249
 })(jQuery);

0 notes on commit cb15dc3

Please sign in to comment.
Something went wrong with that request. Please try again.