From 5c6ec20c7e8f1e068c6cce76361d2e69fd02cd7f Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 8 Dec 2016 16:20:04 -0800 Subject: [PATCH] refactor(router): simplify regexp closes #11373 closes #13329 --- modules/@angular/router/src/url_tree.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/@angular/router/src/url_tree.ts b/modules/@angular/router/src/url_tree.ts index bca907309c..0207f147b0 100644 --- a/modules/@angular/router/src/url_tree.ts +++ b/modules/@angular/router/src/url_tree.ts @@ -393,21 +393,23 @@ function pairs(obj: {[key: string]: T}): Pair[] { return res; } -const SEGMENT_RE = /^[^\/\(\)\?;=&#]+/; +const SEGMENT_RE = /^[^\/()?;=&#]+/; function matchSegments(str: string): string { SEGMENT_RE.lastIndex = 0; const match = str.match(SEGMENT_RE); return match ? match[0] : ''; } -const QUERY_PARAM_RE = /^[^=\?&#]+/; +const QUERY_PARAM_RE = /^[^=?&#]+/; +// Return the name of the query param at the start of the string or an empty string function matchQueryParams(str: string): string { QUERY_PARAM_RE.lastIndex = 0; const match = str.match(SEGMENT_RE); return match ? match[0] : ''; } -const QUERY_PARAM_VALUE_RE = /^[^\?&#]+/; +const QUERY_PARAM_VALUE_RE = /^[^?&#]+/; +// Return the value of the query param at the start of the string or an empty string function matchUrlQueryParamValue(str: string): string { QUERY_PARAM_VALUE_RE.lastIndex = 0; const match = str.match(QUERY_PARAM_VALUE_RE);