koa icon indicating copy to clipboard operation
koa copied to clipboard

[fix] Setter of `request.query` does not save array when length of the array is 1

Open 3jins opened this issue 3 years ago • 2 comments

Describe the bug

Node.js version: 16.10.0

OS version: Mac OS Monterey 12.3.1 (It doesn't matter...)

Description:

Actual behavior

Setter of request.query saves single element instead of the array.

Setter of request.query uses qs.stringify to save the input to request.querystring, and it would be converted into the form like key=value1&key=value2. But when array size is 1, it becomes unable to know whether it's array or string since it would be saved as key=value1. So preprocessing would be necessary I think.

Expected behavior

An array should be saved as I passed.

Code to reproduce

  ctx.query = { tagIdList: ['abcd'] };
  console.log(ctx.query); // It prints out { tagIdList: 'abcd' }

3jins avatar Jun 10 '22 08:06 3jins

A solution was proposed in PR https://github.com/koajs/koa/pull/1673

However, I'm tentatively holding any approvals as I judge this to require a semver major bump, in which case Koa could benefit from other changes as well.

miwnwski avatar Jul 01 '22 18:07 miwnwski