Skip to content

Commit bb78e30

Browse files
committed
do not validate language in filename*
1 parent 88a9eea commit bb78e30

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/
9090
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
9191

9292
/**
93-
* RegExp for various RFC 5987 grammar
93+
* RegExp for parsing extended parameter values per RFC 5987.
9494
*
9595
* ext-value = charset "'" [ language ] "'" value-chars
9696
* charset = "UTF-8" / "ISO-8859-1" / mime-charset
@@ -99,19 +99,20 @@ var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
9999
* / "!" / "#" / "$" / "%" / "&"
100100
* / "+" / "-" / "^" / "_" / "`"
101101
* / "{" / "}" / "~"
102-
* language = ( 2*3ALPHA [ extlang ] )
103-
* / 4ALPHA
104-
* / 5*8ALPHA
105-
* extlang = *3( "-" 3ALPHA )
102+
*
103+
* language = <Language-Tag as defined in RFC 5646, Section 2.1>
104+
* (Optional: the two literal single quotes MUST appear,
105+
* but the language field inside them may be empty.
106+
* We ignoring the language content rather than validate it)
107+
*
106108
* value-chars = *( pct-encoded / attr-char )
107109
* pct-encoded = "%" HEXDIG HEXDIG
108110
* attr-char = ALPHA / DIGIT
109111
* / "!" / "#" / "$" / "&" / "+" / "-" / "."
110112
* / "^" / "_" / "`" / "|" / "~"
111113
* @private
112114
*/
113-
114-
var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/
115+
var EXT_VALUE_REGEXP = /([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[^']*)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/
115116

116117
/**
117118
* RegExp for various RFC 6266 grammar

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,25 @@ describe('contentDisposition.parse(string)', function () {
380380
/unsupported charset/)
381381
})
382382

383+
it('should reject when missing embedded language', function () {
384+
assert.throws(contentDisposition.parse.bind(null, 'attachment; filename*=UTF-8%E2%82%AC%20rates.pdf'),
385+
/invalid extended field value/)
386+
})
387+
383388
it('should parse with embedded language', function () {
384389
assert.deepEqual(contentDisposition.parse('attachment; filename*=UTF-8\'en\'%E2%82%AC%20rates.pdf'), {
385390
type: 'attachment',
386391
parameters: { filename: '€ rates.pdf' }
387392
})
388393
})
389394

395+
it('should parse with embedded language with region subtag', function () {
396+
assert.deepEqual(contentDisposition.parse('attachment; filename*=UTF-8\'en-US\'%E2%82%AC%20rates.pdf'), {
397+
type: 'attachment',
398+
parameters: { filename: '€ rates.pdf' }
399+
})
400+
})
401+
390402
it('should prefer extended parameter value', function () {
391403
assert.deepEqual(contentDisposition.parse('attachment; filename="EURO rates.pdf"; filename*=UTF-8\'\'%E2%82%AC%20rates.pdf'), {
392404
type: 'attachment',

0 commit comments

Comments
 (0)