From 701f2d033bbc421f85f888f9bf9100b176aac818 Mon Sep 17 00:00:00 2001 From: Pim Date: Tue, 12 Nov 2019 17:39:34 +0100 Subject: [PATCH] =?UTF-8?q?fix(vue-app):=20apply=20path-to-regexp=20option?= =?UTF-8?q?s=20to=20tokensToFunction=E2=80=A6=20(#6683)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vue-app/template/utils.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/vue-app/template/utils.js b/packages/vue-app/template/utils.js index f2a50dd983..82ede520a6 100644 --- a/packages/vue-app/template/utils.js +++ b/packages/vue-app/template/utils.js @@ -280,7 +280,7 @@ export function getLocation (base, mode) { * @return {!function(Object=, Object=)} */ export function compile (str, options) { - return tokensToFunction(parse(str, options)) + return tokensToFunction(parse(str, options), options) } export function getQueryDiff (toQuery, fromQuery) { @@ -449,14 +449,14 @@ function escapeGroup (group) { /** * Expose a method for transforming tokens into the path function. */ -function tokensToFunction (tokens) { +function tokensToFunction (tokens, options) { // Compile all the tokens into regexps. const matches = new Array(tokens.length) // Compile all the patterns before compilation. for (let i = 0; i < tokens.length; i++) { if (typeof tokens[i] === 'object') { - matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$') + matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options)) } } @@ -530,6 +530,16 @@ function tokensToFunction (tokens) { } } +/** + * Get the flags for a regexp from the options. + * + * @param {Object} options + * @return {string} + */ +function flags (options) { + return options && options.sensitive ? '' : 'i' +} + /** * Format given url, append query to url query string *