Skip to content

Commit

Permalink
Remove decodeUriParameters option
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed May 18, 2022
1 parent 0212ae4 commit 237825c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 91 deletions.
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,6 @@ Having a route with multiple parameters may affect negatively the performance, s

**Note** that you must encode the parameters containing [reserved characters](https://www.rfc-editor.org/rfc/rfc3986#section-2.2).

If your routes' parameters are not Basic Latin charaters, you may face a performance drop. To avoid it, you can customize the way the parameters are parsed by passing a custom decoding function. Read more about it [here](https://github.com/delvedor/find-my-way/pull/211).
The parsing function is called when the request URL contains one or more encoded special characters: `# $ & + , / : ; = ? @`.

```js
const router = require('find-my-way')({
decodeUriParameters: (stringToDecode) => {
// called when the request URL contains st least one special character: `# $ & + , / : ; = ? @`
return decodeURIComponent(stringToDecode)
}
})
```

By default, this module relies on [fast-decode-uri-component`](https://www.npmjs.com/package/fast-decode-uri-component) to parse the encoded path parameters.

<a name="match-order"></a>
##### Match order

Expand Down
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,13 @@ function Router (opts) {
this.buildPrettyMeta = defaultBuildPrettyMeta
}

if (opts.decodeUriParameters) {
assert(typeof opts.decodeUriParameters === 'function', 'decodeUriParameters must be a function')
this.decodeUriParameters = opts.decodeUriParameters
}

this.caseSensitive = opts.caseSensitive === undefined ? true : opts.caseSensitive
this.ignoreTrailingSlash = opts.ignoreTrailingSlash || false
this.maxParamLength = opts.maxParamLength || 100
this.allowUnsafeRegex = opts.allowUnsafeRegex || false
this.routes = []
this.trees = {}

this.decodeURIComponent = opts.decodeUriParameters || safeDecodeURIComponent
this.constrainer = new Constrainer(opts.constraints)
}

Expand Down Expand Up @@ -440,7 +434,7 @@ Router.prototype.find = function find (method, path, derivedConstraints) {

const firstPercentIndex = param.indexOf('%')
if (firstPercentIndex !== -1) {
param = this.decodeURIComponent(param, firstPercentIndex)
param = safeDecodeURIComponent(param, firstPercentIndex)
}

if (param.length > maxParamLength) {
Expand All @@ -466,7 +460,7 @@ Router.prototype.find = function find (method, path, derivedConstraints) {

let param = originPath.slice(pathIndex, paramEndIndex)
if (firstPercentIndex !== -1) {
param = this.decodeURIComponent(param, firstPercentIndex)
param = safeDecodeURIComponent(param, firstPercentIndex)
}

if (currentNode.isRegex) {
Expand Down
69 changes: 0 additions & 69 deletions test/custom-decode-uri.test.js

This file was deleted.

0 comments on commit 237825c

Please sign in to comment.