m4nuC / async-busboy

Promise based multipart form parser for KoaJS
MIT License
167 stars 58 forks source link

Using form name arrays without defined key name causes a TypeError. #21

Closed jakeandreoli closed 7 years ago

jakeandreoli commented 7 years ago

I found an issue when trying to use array values without a defined key name. This can be easily replicated.

I am unsure if this is an issue in the wrapper or the original code, though the error occurs in the reconcile function, which is not present in the synchronous version; hence why I am sharing the issue here.

<input type="password" name="password[]"> <!-- Should be treated as password[0] -->
<input type="password" name="password[]"> <!-- Should be treated as password[1] -->

The actual error occurring:

TypeError: Cannot create property 'undefined' on string ''
    at reconcile (Path\To\Project\node_modules\async-busboy\index.js:208:24)
    at reconcile (Path\To\Project\node_modules\async-busboy\index.js:206:12)
    at reconcile (Path\To\Project\node_modules\async-busboy\index.js:206:12)
    at onField (Path\To\Project\node_modules\async-busboy\index.js:84:5)
    at emitMany (events.js:127:13)
    at Busboy.emit (events.js:204:7)
    at Busboy.emit (Path\To\Project\node_modules\busboy\lib\main.js:38:33)
    at UrlEncoded.end (Path\To\Project\node_modules\busboy\lib\types\urlencoded.js:205:14)
    at Busboy.emit (Path\To\Project\node_modules\busboy\lib\main.js:31:36)
    at finishMaybe (_stream_writable.js:510:14)
    at endWritable (_stream_writable.js:520:3)
    at Busboy.Writable.end (_stream_writable.js:485:5)
    at IncomingMessage.onend (_stream_readable.js:511:10)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Putting the following works around the issue, however creates problems when dynamically creating elements based on user interaction:

<input type="password" name="password[0]">
<input type="password" name="password[1]">
jakeandreoli commented 7 years ago

I added a pull request that adds support for this #22 and refactored code to allow this to work.

m4nuC commented 7 years ago

Hi @jakeandreoli, thanks for the PR. I've merged #20 to address this problem. I will keep you PR open for now as it might come in handy later.