Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3439)

Unified Diff: chrome/browser/resources/settings/route.js

Issue 2518763002: MD Settings: Allow trailing slashes in otherwise valid URLs. (Closed)
Patch Set: Nit per Tommy's comment. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/settings/route_tests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/route.js
diff --git a/chrome/browser/resources/settings/route.js b/chrome/browser/resources/settings/route.js
index 082a46d3015bbb5cc8493b9a4b3b5967eeef5102..5f6750f165a031df5dcc530a71a22389c56c1859 100644
--- a/chrome/browser/resources/settings/route.js
+++ b/chrome/browser/resources/settings/route.js
@@ -238,17 +238,27 @@ cr.define('settings', function() {
};
/**
- * Returns the matching canonical route, or null if none matches.
+ * Regular expression that captures the leading slash, the content and the
+ * trailing slash in three different groups.
+ * @const {!RegExp}
+ */
+ var CANONICAL_PATH_REGEX = /(^\/)([\/-\w]+)(\/$)/;
+
+ /**
* @param {string} path
- * @return {?settings.Route}
+ * @return {?settings.Route} The matching canonical route, or null if none
+ * matches.
*/
var getRouteForPath = function(path) {
+ // Allow trailing slash in paths.
+ var canonicalPath = path.replace(CANONICAL_PATH_REGEX, '$1$2');
+
// TODO(tommycli): Use Object.values once Closure compilation supports it.
var matchingKey = Object.keys(Route).find(function(key) {
- return Route[key].path == path;
+ return Route[key].path == canonicalPath;
});
- return Route[matchingKey] || null;
+ return !!matchingKey ? Route[matchingKey] : null;
};
/**
« no previous file with comments | « no previous file | chrome/test/data/webui/settings/route_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698