From f27be45528d6885f08675ee1c650897e44d3dbfa Mon Sep 17 00:00:00 2001 From: Imed Jaberi Date: Mon, 8 Apr 2024 21:37:26 +0100 Subject: [PATCH] Add koa as peerDeps and fix the encoding option propagation (#160) ## Description Fix #155 and #157 ## Checklist - [x] I have ensured my pull request is not behind the main or master branch of the original repository. - [x] I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first. - [x] I have written a commit message that passes commitlint linting. - [x] I have ensured that my code changes pass linting tests. - [x] I have ensured that my code changes pass unit tests. - [x] I have described my pull request and the reasons for code changes along with context if necessary. --- package.json | 5 ++++- src/body-parser.ts | 2 ++ test/middleware.test.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9c9d785..230f76d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@koa/bodyparser", - "version": "5.1.0", + "version": "5.1.1", "description": "Koa body parsing middleware", "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -69,6 +69,9 @@ "lodash.merge": "^4.6.2", "type-is": "^1.6.18" }, + "peerDependencies": { + "koa": "^2.14.1" + }, "engines": { "node": ">= 16" }, diff --git a/src/body-parser.ts b/src/body-parser.ts index 569a9e2..454978a 100644 --- a/src/body-parser.ts +++ b/src/body-parser.ts @@ -66,6 +66,8 @@ export function bodyParserWrapper(opts: BodyParserOptions = {}) { strict: bodyType === 'json' ? restOpts.jsonStrict : undefined, [`${bodyType}Types`]: mimeTypes[bodyType], limit: restOpts[`${shouldParseBodyAs('xml') ? 'xml' : bodyType}Limit`], + // eslint-disable-next-line unicorn/text-encoding-identifier-case + encoding: restOpts.encoding || 'utf-8', }; return parser[bodyType](ctx, parserOptions) as Promise< diff --git a/test/middleware.test.ts b/test/middleware.test.ts index 49103de..9b7f1eb 100644 --- a/test/middleware.test.ts +++ b/test/middleware.test.ts @@ -56,7 +56,7 @@ describe("test/body-parser.test.ts", () => { .expect({ foo: "bar" }); }); - it.only("should parse json body with `content-type: application/json;charset=utf-8;` headers ok", async () => { + it("should parse json body with `content-type: application/json;charset=utf-8;` headers ok", async () => { app.use(bodyParser()); app.use(async (ctx) => {