diff options
author | Egor Tensin <egor@tensin.name> | 2024-01-28 11:18:12 +0100 |
---|---|---|
committer | Egor Tensin <egor@tensin.name> | 2024-01-28 11:18:12 +0100 |
commit | 2d40e8046a08373b1740922690b695a16d5e5fa6 (patch) | |
tree | eb086741d1bb01ef9ed3d0ac8e1301447e835971 /node_modules/@fastify/busboy/lib/utils/Decoder.js | |
parent | workflows/test: upgrade actions (diff) | |
download | cleanup-path-2d40e8046a08373b1740922690b695a16d5e5fa6.tar.gz cleanup-path-2d40e8046a08373b1740922690b695a16d5e5fa6.zip |
bump version in package.json, upgrade dependencies
Diffstat (limited to 'node_modules/@fastify/busboy/lib/utils/Decoder.js')
-rw-r--r-- | node_modules/@fastify/busboy/lib/utils/Decoder.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/@fastify/busboy/lib/utils/Decoder.js b/node_modules/@fastify/busboy/lib/utils/Decoder.js new file mode 100644 index 0000000..7917678 --- /dev/null +++ b/node_modules/@fastify/busboy/lib/utils/Decoder.js @@ -0,0 +1,54 @@ +'use strict' + +const RE_PLUS = /\+/g + +const HEX = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +] + +function Decoder () { + this.buffer = undefined +} +Decoder.prototype.write = function (str) { + // Replace '+' with ' ' before decoding + str = str.replace(RE_PLUS, ' ') + let res = '' + let i = 0; let p = 0; const len = str.length + for (; i < len; ++i) { + if (this.buffer !== undefined) { + if (!HEX[str.charCodeAt(i)]) { + res += '%' + this.buffer + this.buffer = undefined + --i // retry character + } else { + this.buffer += str[i] + ++p + if (this.buffer.length === 2) { + res += String.fromCharCode(parseInt(this.buffer, 16)) + this.buffer = undefined + } + } + } else if (str[i] === '%') { + if (i > p) { + res += str.substring(p, i) + p = i + } + this.buffer = '' + ++p + } + } + if (p < len && this.buffer === undefined) { res += str.substring(p) } + return res +} +Decoder.prototype.reset = function () { + this.buffer = undefined +} + +module.exports = Decoder |