Chromium Code Reviews| 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..fe7612f7c8f62076ca1779d10741e7a8ddf38421 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]{1,})(\/$)/; |
|
tommycli
2016/11/24 00:02:51
Any particular reason to use {1,} instead of +? ju
tommycli
2016/11/24 00:04:07
Instead of just "+"
Question mark is for the ques
dpapad
2016/11/24 00:07:41
Yes. I need to ensure that there is at least on ch
dpapad
2016/11/24 01:54:09
Done. I double checked and {1,} is equivalent to +
|
| + |
| + /** |
| * @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; |
| }; |
| /** |