Skip to content

Commit

Permalink
use fast-decode-uri-component (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Jan 13, 2023
1 parent 3ec3d1d commit 75e0ff4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
21 changes: 2 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const path = require('path')
const statuses = require('statuses')
const Stream = require('stream')
const util = require('util')
const decode = require('fast-decode-uri-component')

/**
* Path function references.
Expand Down Expand Up @@ -427,7 +428,7 @@ SendStream.prototype.pipe = function pipe (res) {

// decode the path
let path = decode(this.path)
if (path === -1) {
if (path === null) {
this.error(400)
return res
}
Expand Down Expand Up @@ -904,24 +905,6 @@ function createHttpError (status, err) {
: createError(status, err)
}

/**
* decodeURIComponent.
*
* Allows V8 to only deoptimize this fn instead of all
* of send().
*
* @param {String} path
* @api private
*/

function decode (path) {
try {
return decodeURIComponent(path)
} catch (err) {
return -1
}
}

/**
* Normalize the index option into an array.
*
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fast-decode-uri-component": "^1.0.1",
"fresh": "0.5.2",
"http-errors": "2.0.0",
"mime": "^3.0.0",
Expand Down

0 comments on commit 75e0ff4

Please sign in to comment.