Skip to content

Commit

Permalink
Fix parse to accept any linear whitespace character
Browse files Browse the repository at this point in the history
fixes #12
  • Loading branch information
dougwilson committed Dec 9, 2016
1 parent cb4ba52 commit c63bfdd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix `parse` to accept any linear whitespace character

0.5.1 / 2016-01-17
==================

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var QUOTE_REGEXP = /([\\"])/g
* OCTET = <any 8-bit sequence of data>
*/

var PARAM_REGEXP = /; *([!#$%&'*+.0-9A-Z^_`a-z|~-]+) *= *("(?:[ !\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+) */g
var PARAM_REGEXP = /;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g // eslint-disable-line no-control-regex
var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/

Expand Down Expand Up @@ -117,7 +117,7 @@ var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-
* ext-token = <the characters in token, followed by "*">
*/

var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+) *(?:$|;)/
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex

/**
* Create an attachment Content-Disposition header.
Expand Down
9 changes: 8 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('contentDisposition.parse(string)', function () {
})

it('should parse with trailing LWS', function () {
assert.deepEqual(contentDisposition.parse('attachment '), {
assert.deepEqual(contentDisposition.parse('attachment \t '), {
type: 'attachment',
parameters: {}
})
Expand Down Expand Up @@ -304,6 +304,13 @@ describe('contentDisposition.parse(string)', function () {
})
})

it('should parse parameters separated with any LWS', function () {
assert.deepEqual(contentDisposition.parse('attachment;filename="plans.pdf" \t; \t\t foo=bar'), {
type: 'attachment',
parameters: { filename: 'plans.pdf', foo: 'bar' }
})
})

it('should parse token filename', function () {
assert.deepEqual(contentDisposition.parse('attachment; filename=plans.pdf'), {
type: 'attachment',
Expand Down

0 comments on commit c63bfdd

Please sign in to comment.