fix(vue-app): apply path-to-regexp options to tokensToFunction… (#6683)

This commit is contained in:
Pim 2019-11-12 17:39:34 +01:00 committed by Xin Du (Clark)
parent 2338d3c4f3
commit 701f2d033b

View File

@ -280,7 +280,7 @@ export function getLocation (base, mode) {
* @return {!function(Object=, Object=)} * @return {!function(Object=, Object=)}
*/ */
export function compile (str, options) { export function compile (str, options) {
return tokensToFunction(parse(str, options)) return tokensToFunction(parse(str, options), options)
} }
export function getQueryDiff (toQuery, fromQuery) { export function getQueryDiff (toQuery, fromQuery) {
@ -449,14 +449,14 @@ function escapeGroup (group) {
/** /**
* Expose a method for transforming tokens into the path function. * Expose a method for transforming tokens into the path function.
*/ */
function tokensToFunction (tokens) { function tokensToFunction (tokens, options) {
// Compile all the tokens into regexps. // Compile all the tokens into regexps.
const matches = new Array(tokens.length) const matches = new Array(tokens.length)
// Compile all the patterns before compilation. // Compile all the patterns before compilation.
for (let i = 0; i < tokens.length; i++) { for (let i = 0; i < tokens.length; i++) {
if (typeof tokens[i] === 'object') { 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 * Format given url, append query to url query string
* *