Skip to content

Content-Disposition filename* decoding #203

@Vladislao

Description

@Vladislao

Hey there! Thanks for such a great tool!

It seems that there is a problem with filename* decoding for multipart data. Having the content-disposition header like that for a part "form-data; name=fileName; filename*=utf-8''1_%D0%9B%D0%B8%D1%81%D1%821.html" file callback provides incorrect filename.

I've been digging into it recently and noticed something odd.

if (header['content-disposition']) {
parsed = parseParams(header['content-disposition'][0]);
if (!RE_FIELD.test(parsed[0]))
return skipPart(part);
for (i = 0, len = parsed.length; i < len; ++i) {
if (RE_NAME.test(parsed[i][0])) {
fieldname = decodeText(parsed[i][1], 'binary', 'utf8');
} else if (RE_FILENAME.test(parsed[i][0])) {
filename = decodeText(parsed[i][1], 'binary', 'utf8');

busboy/lib/utils.js

Lines 78 to 82 in da0e67d

if (charset && tmp.length) {
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
'binary',
charset);
}

parseParams internally decodes filename into specified encoding, so parsed contains already decoded filename. On line 159 filename is decoded again having binary as current encoding and returns incorrect result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions