@fastify/busboy
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -43,2 +43,3 @@ 'use strict' | ||
const needleLength = needle.length | ||
const needleLastCharIndex = needleLength - 1 | ||
@@ -56,3 +57,3 @@ if (needleLength === 0) { | ||
this._occ = new Array(256) | ||
this._occ = new Uint8Array(256) | ||
.fill(needleLength) // Initialize occurrence table. | ||
@@ -63,8 +64,8 @@ this._lookbehind_size = 0 | ||
this._lookbehind = Buffer.alloc(needleLength) | ||
this._lookbehind = Buffer.alloc(needleLastCharIndex) | ||
// Populate occurrence table with analysis of the needle, | ||
// ignoring last letter. | ||
for (var i = 0; i < needleLength - 1; ++i) { // eslint-disable-line no-var | ||
this._occ[needle[i]] = needleLength - 1 - i | ||
for (var i = 0; i < needleLastCharIndex; ++i) { // eslint-disable-line no-var | ||
this._occ[needle[i]] = needleLastCharIndex - i | ||
} | ||
@@ -95,3 +96,4 @@ } | ||
const needleLength = needle.length | ||
const lastNeedleChar = needle[needleLength - 1] | ||
const needleLastCharIndex = needleLength - 1 | ||
const needleLastChar = needle[needleLastCharIndex] | ||
@@ -119,7 +121,7 @@ // Positive: points to a position in `data` | ||
while (pos < 0 && pos <= len - needleLength) { | ||
ch = this._sbmh_lookup_char(data, pos + needleLength - 1) | ||
ch = this._sbmh_lookup_char(data, pos + needleLastCharIndex) | ||
if ( | ||
ch === lastNeedleChar && | ||
this._sbmh_memcmp(data, pos, needleLength - 1) | ||
ch === needleLastChar && | ||
this._sbmh_memcmp(data, pos, needleLastCharIndex) | ||
) { | ||
@@ -129,5 +131,5 @@ this._lookbehind_size = 0 | ||
this.emit('info', true) | ||
return (this._bufpos = pos + needleLength) | ||
} | ||
pos += this._occ[ch] | ||
@@ -138,3 +140,3 @@ } | ||
if (pos < 0) { | ||
while (pos < 0 && !this._sbmh_memcmp(data, pos, len - pos)) { | ||
// There's too few data for Boyer-Moore-Horspool to run, | ||
@@ -148,3 +150,3 @@ // so let's use a different algorithm to skip as much as | ||
// pos == 0 | ||
while (pos < 0 && !this._sbmh_memcmp(data, pos, len - pos)) { ++pos } | ||
++pos | ||
} | ||
@@ -179,11 +181,14 @@ | ||
// needle is in the haystack. | ||
pos = data.indexOf(needle, pos + ((pos >= 0) * this._bufpos)) | ||
pos = data.indexOf(needle, pos + this._bufpos) | ||
if (pos !== -1) { | ||
++this.matches | ||
if (pos > 0) { this.emit('info', true, data, this._bufpos, pos) } else { this.emit('info', true) } | ||
if (pos === 0) { this.emit('info', true) } else { this.emit('info', true, data, this._bufpos, pos) } | ||
return (this._bufpos = pos + needleLength) | ||
} | ||
pos = len - needleLength | ||
pos = len - needleLastCharIndex | ||
if (pos < 0) { | ||
pos = 0 | ||
} | ||
@@ -197,8 +202,8 @@ // There was no match. If there's trailing haystack data that we cannot | ||
while ( | ||
pos < len && | ||
pos !== len && | ||
( | ||
data[pos] !== needle[0] || | ||
Buffer.compare( | ||
data.subarray(pos, pos + len - pos), | ||
needle.subarray(0, len - pos) | ||
data.subarray(pos + 1, len), | ||
needle.subarray(1, len - pos) | ||
) !== 0 | ||
@@ -209,4 +214,5 @@ ) | ||
} | ||
if (pos < len) { | ||
data.copy(this._lookbehind, 0, pos, pos + (len - pos)) | ||
if (pos !== len) { | ||
data.copy(this._lookbehind, 0, pos, len) | ||
this._lookbehind_size = len - pos | ||
@@ -216,3 +222,3 @@ } | ||
// Everything until pos is guaranteed not to contain needle data. | ||
if (pos > 0) { this.emit('info', false, data, this._bufpos, pos < len ? pos : len) } | ||
if (pos !== 0) { this.emit('info', false, data, this._bufpos, pos) } | ||
@@ -219,0 +225,0 @@ this._bufpos = len |
@@ -36,7 +36,7 @@ // Definitions by: Jacob Baskin <https://github.com/jacobbaskin> | ||
* Detect if a Part is a file. | ||
* | ||
* By default a file is detected if contentType | ||
* | ||
* By default a file is detected if contentType | ||
* is application/octet-stream or fileName is not | ||
* undefined. | ||
* | ||
* | ||
* Modify this to handle e.g. Blobs. | ||
@@ -43,0 +43,0 @@ */ |
{ | ||
"name": "@fastify/busboy", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"private": false, | ||
@@ -27,20 +27,18 @@ "author": "Brian White <mscdex@mscdex.net>", | ||
"lint": "npm run lint:standard", | ||
"lint:everything": "npm run lint && npm run test:types", | ||
"lint:fix": "standard --fix", | ||
"lint:standard": "standard --verbose | snazzy", | ||
"test:mocha": "tap", | ||
"test:unit": "c8 --statements 98 --branches 97 --functions 96 --lines 98 node --test", | ||
"test:types": "tsd", | ||
"test:coverage": "nyc npm run test", | ||
"test": "npm run test:mocha" | ||
"test": "npm run test:unit && npm run test:types" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.30", | ||
"@types/node": "^22.0.0", | ||
"busboy": "^1.6.0", | ||
"c8": "^10.1.2", | ||
"photofinish": "^1.8.0", | ||
"snazzy": "^9.0.0", | ||
"standard": "^17.1.0", | ||
"tap": "^18.7.1", | ||
"tinybench": "^2.6.0", | ||
"tinybench": "^3.0.0", | ||
"tsd": "^0.31.0", | ||
"typescript": "^5.4.3" | ||
"typescript": "~5.7.2" | ||
}, | ||
@@ -58,2 +56,6 @@ "keywords": [ | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fastify/busboy/issues" | ||
}, | ||
"homepage": "https://github.com/fastify/busboy#readme", | ||
"tsd": { | ||
@@ -60,0 +62,0 @@ "directory": "test/types", |
@@ -6,3 +6,2 @@ # busboy | ||
[![Build Status](https://github.com/fastify/busboy/actions/workflows/ci.yml/badge.svg)](https://github.com/fastify/busboy/actions) | ||
[![Coverage Status](https://coveralls.io/repos/fastify/busboy/badge.svg?branch=master)](https://coveralls.io/r/fastify/busboy?branch=master) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
@@ -57,3 +56,3 @@ [![Security Responsible Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/fastify/.github/blob/main/SECURITY.md) | ||
const { inspect } = require('node:util'); | ||
const Busboy = require('busboy'); | ||
const Busboy = require('@fastify/busboy'); | ||
@@ -113,3 +112,3 @@ http.createServer((req, res) => { | ||
const Busboy = require('busboy'); | ||
const Busboy = require('@fastify/busboy'); | ||
@@ -142,3 +141,3 @@ http.createServer(function(req, res) { | ||
const Busboy = require('busboy'); | ||
const Busboy = require('@fastify/busboy'); | ||
@@ -271,3 +270,3 @@ http.createServer(function(req, res) { | ||
* **Limit $limit is not a valid number** - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number. | ||
* **Limit $limit is not a valid number** - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number. | ||
@@ -274,0 +273,0 @@ * **Unsupported Content-Type.** - The `Content-Type` isn't one Busboy can parse. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
80136
1675
0
0
0
271