Skip to content

Commit 632a237

Browse files
authored
Merge commit from fork
1 parent 957a24b commit 632a237

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎deps/streamsearch/sbmh.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function SBMH (needle) {
5353
this.maxMatches = Infinity
5454
this.matches = 0
5555

56-
this._occ = new Uint8Array(256)
56+
this._occ = new Uint16Array(256)
5757
.fill(needleLength) // Initialize occurrence table.
5858
this._lookbehind_size = 0
5959
this._needle = needle

‎test/multipart-constructor.test.js‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
'use strict'
22

3+
const { spawnSync } = require('node:child_process')
4+
const { test } = require('node:test')
35
const Multipart = require('../lib/types/multipart')
46
const Busboy = require('..')
5-
const { test } = require('node:test')
67

7-
test('multipart constructor', t => {
8-
t.plan(1)
8+
test('multipart constructor', async t => {
9+
t.plan(2)
910

10-
t.test('throws if the boundary is not a string', t => {
11+
await t.test('throws if the boundary is not a string', t => {
1112
const busboy = new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
1213

1314
t.assert.throws(() => new Multipart(busboy, { boundary: 123 }), { message: 'Multipart: Boundary not found' })
1415
t.assert.ok('end')
1516
})
17+
18+
await t.test('processes a fragmented 252-byte boundary without hanging', t => {
19+
t.plan(1)
20+
21+
const script = `
22+
const Busboy = require(${JSON.stringify(require.resolve('..'))})
23+
const boundary = 'A'.repeat(252)
24+
const parser = Busboy({
25+
headers: { 'content-type': 'multipart/form-data; boundary=' + boundary }
26+
})
27+
parser.write(Buffer.from('--' + boundary.slice(0, -1)))
28+
parser.write(Buffer.from('X'), (error) => process.exit(error ? 1 : 0))
29+
setTimeout(() => process.exit(1), 500)
30+
`
31+
const result = spawnSync(process.execPath, ['-e', script], { timeout: 2000 })
32+
33+
t.assert.deepStrictEqual(
34+
{ error: result.error && result.error.code, signal: result.signal, status: result.status },
35+
{ error: undefined, signal: null, status: 0 }
36+
)
37+
})
1638
})

‎test/streamsearch.test.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { test } = require('node:test')
44
const Streamsearch = require('../deps/streamsearch/sbmh')
55

66
test('streamsearch', async t => {
7-
t.plan(19)
7+
t.plan(20)
88

99
await t.test('should throw an error if the needle is not a String or Buffer', t => {
1010
t.plan(1)
@@ -27,6 +27,14 @@ test('streamsearch', async t => {
2727
t.assert.throws(() => new Streamsearch(Buffer.from(Array(257).fill('a').join(''))), { message: 'The needle cannot have a length bigger than 256.' })
2828
})
2929

30+
await t.test('should represent the maximum skip distance', t => {
31+
t.plan(1)
32+
33+
const search = new Streamsearch(Buffer.alloc(256, 0x41))
34+
35+
t.assert.strictEqual(search._occ[0x42], 256)
36+
})
37+
3038
await t.test('should process a Buffer without a needle', t => {
3139
t.plan(5)
3240
const expected = [

0 commit comments

Comments
 (0)