Aktueller Stand
This commit is contained in:
48
backend/node_modules/find-my-way/index.js
generated
vendored
48
backend/node_modules/find-my-way/index.js
generated
vendored
@@ -38,6 +38,8 @@ const { safeDecodeURI, safeDecodeURIComponent } = require('./lib/url-sanitizer')
|
||||
|
||||
const FULL_PATH_REGEXP = /^https?:\/\/.*?\//
|
||||
const OPTIONAL_PARAM_REGEXP = /(\/:[^/()]*?)\?(\/?)/
|
||||
const ESCAPE_REGEXP = /[.*+?^${}()|[\]\\]/g
|
||||
const REMOVE_DUPLICATE_SLASHES_REGEXP = /\/\/+/g
|
||||
|
||||
if (!isRegexSafe(FULL_PATH_REGEXP)) {
|
||||
throw new Error('the FULL_PATH_REGEXP is not safe, update this module')
|
||||
@@ -47,6 +49,14 @@ if (!isRegexSafe(OPTIONAL_PARAM_REGEXP)) {
|
||||
throw new Error('the OPTIONAL_PARAM_REGEXP is not safe, update this module')
|
||||
}
|
||||
|
||||
if (!isRegexSafe(ESCAPE_REGEXP)) {
|
||||
throw new Error('the ESCAPE_REGEXP is not safe, update this module')
|
||||
}
|
||||
|
||||
if (!isRegexSafe(REMOVE_DUPLICATE_SLASHES_REGEXP)) {
|
||||
throw new Error('the REMOVE_DUPLICATE_SLASHES_REGEXP is not safe, update this module')
|
||||
}
|
||||
|
||||
function Router (opts) {
|
||||
if (!(this instanceof Router)) {
|
||||
return new Router(opts)
|
||||
@@ -79,7 +89,7 @@ function Router (opts) {
|
||||
assert(typeof opts.querystringParser === 'function', 'querystringParser must be a function')
|
||||
this.querystringParser = opts.querystringParser
|
||||
} else {
|
||||
this.querystringParser = (query) => query === '' ? {} : querystring.parse(query)
|
||||
this.querystringParser = (query) => query.length === 0 ? {} : querystring.parse(query)
|
||||
}
|
||||
|
||||
this.caseSensitive = opts.caseSensitive === undefined ? true : opts.caseSensitive
|
||||
@@ -184,8 +194,8 @@ Router.prototype._on = function _on (method, path, opts, handler, store) {
|
||||
if (!this.caseSensitive) {
|
||||
staticNodePath = staticNodePath.toLowerCase()
|
||||
}
|
||||
staticNodePath = staticNodePath.split('::').join(':')
|
||||
staticNodePath = staticNodePath.split('%').join('%25')
|
||||
staticNodePath = staticNodePath.replaceAll('::', ':')
|
||||
staticNodePath = staticNodePath.replaceAll('%', '%25')
|
||||
// add the static part of the route to the tree
|
||||
currentNode = currentNode.createStaticChild(staticNodePath)
|
||||
}
|
||||
@@ -240,8 +250,8 @@ Router.prototype._on = function _on (method, path, opts, handler, store) {
|
||||
|
||||
let staticPart = pattern.slice(staticPartStartIndex, j)
|
||||
if (staticPart) {
|
||||
staticPart = staticPart.split('::').join(':')
|
||||
staticPart = staticPart.split('%').join('%25')
|
||||
staticPart = staticPart.replaceAll('::', ':')
|
||||
staticPart = staticPart.replaceAll('%', '%25')
|
||||
regexps.push(backtrack = escapeRegExp(staticPart))
|
||||
}
|
||||
|
||||
@@ -328,8 +338,8 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
|
||||
if (!this.caseSensitive) {
|
||||
staticNodePath = staticNodePath.toLowerCase()
|
||||
}
|
||||
staticNodePath = staticNodePath.split('::').join(':')
|
||||
staticNodePath = staticNodePath.split('%').join('%25')
|
||||
staticNodePath = staticNodePath.replaceAll('::', ':')
|
||||
staticNodePath = staticNodePath.replaceAll('%', '%25')
|
||||
// add the static part of the route to the tree
|
||||
currentNode = currentNode.getStaticChild(staticNodePath)
|
||||
if (currentNode === null) {
|
||||
@@ -387,8 +397,8 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
|
||||
|
||||
let staticPart = pattern.slice(staticPartStartIndex, j)
|
||||
if (staticPart) {
|
||||
staticPart = staticPart.split('::').join(':')
|
||||
staticPart = staticPart.split('%').join('%25')
|
||||
staticPart = staticPart.replaceAll('::', ':')
|
||||
staticPart = staticPart.replaceAll('%', '%25')
|
||||
regexps.push(backtrack = escapeRegExp(staticPart))
|
||||
}
|
||||
|
||||
@@ -752,14 +762,22 @@ Router.prototype.all = function (path, handler, store) {
|
||||
this.on(httpMethods, path, handler, store)
|
||||
}
|
||||
|
||||
Router.sanitizeUrlPath = function sanitizeUrlPath (url, useSemicolonDelimiter) {
|
||||
const decoded = safeDecodeURI(url, useSemicolonDelimiter)
|
||||
if (decoded.shouldDecodeParam) {
|
||||
return safeDecodeURIComponent(decoded.path)
|
||||
}
|
||||
return decoded.path
|
||||
}
|
||||
|
||||
module.exports = Router
|
||||
|
||||
function escapeRegExp (string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
return string.replace(ESCAPE_REGEXP, '\\$&')
|
||||
}
|
||||
|
||||
function removeDuplicateSlashes (path) {
|
||||
return path.replace(/\/\/+/g, '/')
|
||||
return path.indexOf('//') !== -1 ? path.replace(REMOVE_DUPLICATE_SLASHES_REGEXP, '/') : path
|
||||
}
|
||||
|
||||
function trimLastSlash (path) {
|
||||
@@ -792,15 +810,15 @@ function getClosingParenthensePosition (path, idx) {
|
||||
while (idx < path.length) {
|
||||
idx++
|
||||
|
||||
// ignore skipped chars
|
||||
if (path[idx] === '\\') {
|
||||
// ignore skipped chars "\"
|
||||
if (path.charCodeAt(idx) === 92) {
|
||||
idx++
|
||||
continue
|
||||
}
|
||||
|
||||
if (path[idx] === ')') {
|
||||
if (path.charCodeAt(idx) === 41) {
|
||||
parentheses--
|
||||
} else if (path[idx] === '(') {
|
||||
} else if (path.charCodeAt(idx) === 40) {
|
||||
parentheses++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user