From 5224f925f76891885437276279f981da24c37345 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:13:42 +0100 Subject: [PATCH] style: `check:fix` --- src/content-types/index.ts | 4 +- src/utils/split-multipart.ts | 12 ++-- tests/parsers/multipart.test.ts | 101 ++++++-------------------------- 3 files changed, 25 insertions(+), 92 deletions(-) diff --git a/src/content-types/index.ts b/src/content-types/index.ts index 1eb12d1..d11decd 100644 --- a/src/content-types/index.ts +++ b/src/content-types/index.ts @@ -1,7 +1,7 @@ export * from './custom' export * from './json' -export * from "./multipart-form-data" +export * from './multipart-form-data' export * from './raw' -export * from "./raw-multipart" +export * from './raw-multipart' export * from './text' export * from './urlencoded' diff --git a/src/utils/split-multipart.ts b/src/utils/split-multipart.ts index 6b895af..58f42b3 100644 --- a/src/utils/split-multipart.ts +++ b/src/utils/split-multipart.ts @@ -1,18 +1,18 @@ import { Buffer } from 'node:buffer' -import { ClientError } from "@otterhttp/errors"; +import { ClientError } from '@otterhttp/errors' -const doubleHyphen = Buffer.from("--") -const CRLF = Buffer.from("\r\n") -const linearWhitespace = Buffer.from(" \t") +const doubleHyphen = Buffer.from('--') +const CRLF = Buffer.from('\r\n') +const linearWhitespace = Buffer.from(' \t') function isWhitespaceCharCode(charCode: number | undefined): boolean { return charCode === linearWhitespace.at(0) || charCode === linearWhitespace.at(1) } function fail(): never { - throw new ClientError("Invalid multipart data", { + throw new ClientError('Invalid multipart data', { statusCode: 400, - code: "ERR_INVALID_MULTIPART_DATA", + code: 'ERR_INVALID_MULTIPART_DATA', }) } diff --git a/tests/parsers/multipart.test.ts b/tests/parsers/multipart.test.ts index dbf4e76..a84cf6c 100644 --- a/tests/parsers/multipart.test.ts +++ b/tests/parsers/multipart.test.ts @@ -59,65 +59,40 @@ it('should parse valid multipart with multiple parts', () => { }) it('should parse valid multipart form data with blank part', () => { - const multipart = [ - 'preamble', - '--boundary', - '', - '', - '--boundary--', - 'epilogue', - ].join('\r\n') + const multipart = ['preamble', '--boundary', '', '', '--boundary--', 'epilogue'].join('\r\n') expect(parseMultipart(Buffer.from(multipart), 'boundary')).toEqual([ { headers: {}, - content: Buffer.from(""), - } + content: Buffer.from(''), + }, ]) }) it('should parse valid multipart form data with no preamble', () => { - const multipart = [ - '--boundary', - '', - '', - '--boundary--', - 'epilogue', - ].join('\r\n') + const multipart = ['--boundary', '', '', '--boundary--', 'epilogue'].join('\r\n') expect(parseMultipart(Buffer.from(multipart), 'boundary')).toEqual([ { headers: {}, - content: Buffer.from(""), - } + content: Buffer.from(''), + }, ]) }) it('should parse valid multipart form data with no epilogue', () => { - const multipart = [ - 'preamble', - '--boundary', - '', - '', - '--boundary--', - ].join('\r\n') + const multipart = ['preamble', '--boundary', '', '', '--boundary--'].join('\r\n') expect(parseMultipart(Buffer.from(multipart), 'boundary')).toEqual([ { headers: {}, - content: Buffer.from(""), - } + content: Buffer.from(''), + }, ]) }) it('should reject multipart form data with missing CRLF to separate headerlines from content', () => { - const multipart = [ - 'preamble', - '--boundary', - '', - '--boundary--', - 'epilogue', - ].join('\r\n') + const multipart = ['preamble', '--boundary', '', '--boundary--', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') @@ -125,15 +100,7 @@ it('should reject multipart form data with missing CRLF to separate headerlines }) it('should reject multipart form data with invalid part header-lines', () => { - const multipart = [ - 'preamble', - '--boundary', - '--boundary', - '', - 'foobar', - '--boundary--', - 'epilogue', - ].join('\r\n') + const multipart = ['preamble', '--boundary', '--boundary', '', 'foobar', '--boundary--', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') @@ -141,11 +108,7 @@ it('should reject multipart form data with invalid part header-lines', () => { }) it('should reject multipart form data with no parts', () => { - const multipart = [ - 'preamble', - '--boundary--', - 'epilogue' - ].join('\r\n') + const multipart = ['preamble', '--boundary--', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') @@ -153,14 +116,7 @@ it('should reject multipart form data with no parts', () => { }) it('should reject multipart form data with no close delimiter', () => { - const multipart = [ - 'preamble', - '--boundary', - '', - '', - '--boundary', - 'epilogue', - ].join('\r\n') + const multipart = ['preamble', '--boundary', '', '', '--boundary', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') @@ -168,14 +124,7 @@ it('should reject multipart form data with no close delimiter', () => { }) it('should reject multipart form data with non-linear-whitespace characters on a boundary line', () => { - const multipart = [ - 'preamble', - '--boundary eeee', - '', - '', - '--boundary--', - 'epilogue', - ].join('\r\n') + const multipart = ['preamble', '--boundary eeee', '', '', '--boundary--', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') @@ -183,17 +132,7 @@ it('should reject multipart form data with non-linear-whitespace characters on a }) it('should reject multipart form data with parts after a close delimiter', () => { - const multipart = [ - 'preamble', - '--boundary', - '', - '', - '--boundary--', - '', - '', - '--boundary', - 'epilogue', - ].join('\r\n') + const multipart = ['preamble', '--boundary', '', '', '--boundary--', '', '', '--boundary', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') @@ -201,15 +140,9 @@ it('should reject multipart form data with parts after a close delimiter', () => }) it('should reject multipart form data with non-linear-whitespace characters on a boundary line with no preamble', () => { - const multipart = [ - '--boundary eeee', - '', - '', - '--boundary--', - 'epilogue', - ].join('\r\n') + const multipart = ['--boundary eeee', '', '', '--boundary--', 'epilogue'].join('\r\n') expect(() => { parseMultipart(Buffer.from(multipart), 'boundary') }).toThrow() -}) \ No newline at end of file +})