Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ exports.params = (value) => {
// Split at the first "=" only, as a value such as a multipart boundary
// may contain more.
const [key, ...rest] = string_.split(/ *= */);
const value = rest.join('=');
let val = rest.join('=');

if (key && value && exports.isSafeKey(key)) object[key] = value;
if (key && val && exports.isSafeKey(key)) {
if (val.startsWith('"') && val.endsWith('"') && val.length >= 2) {
val = val.slice(1, -1).replace(/\\(.)/g, '$1');
}

object[key] = val;
}
}

return object;
Expand Down
5 changes: 5 additions & 0 deletions test/node/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('utils.params(str)', () => {
.params('multipart/mixed; boundary=----=_Part_0_1; charset=utf-8')
.should.eql({ boundary: '----=_Part_0_1', charset: 'utf-8' });
});

it('should strip quotes from quoted parameter values', () => {
const object = utils.params('text/html; charset="UTF-8"');
object.charset.should.equal('UTF-8');
});
});

describe('utils.parseLinks(str)', () => {
Expand Down