content-disposition-attachment
Advanced tools
Comparing version 0.1.2 to 0.2.0
28
index.js
@@ -129,11 +129,7 @@ class ParseError extends Error { | ||
parseParm () { | ||
let key = this.expect(this.parseToken(), 'expect token') | ||
const key = this.expect(this.parseToken(), 'expect token') | ||
this.expect(this.eat$0(/^\s*=\s*/), 'expect \'=\'') | ||
let value | ||
if (/\*$/.test(key)) { | ||
key = key.slice(0, -1) | ||
value = this.expect(this.parseExtValue(), 'expect ext-value') | ||
} else { | ||
value = this.expect(this.parseValue(), 'expect value') | ||
} | ||
const value = /\*$/.test(key) | ||
? this.expect(this.parseExtValue(), 'expect ext-value') | ||
: this.expect(this.parseValue(), 'expect value') | ||
return { key, value } | ||
@@ -150,14 +146,22 @@ } | ||
const result = { attachment: true } | ||
const exts = {} | ||
this.eatSpaces() | ||
while (this.eat$0(/^;/)) { | ||
this.eatSpaces() | ||
let target = result | ||
let { key, value } = this.parseParm() | ||
if (/^filename$/i.test(key)) { | ||
key = 'filename' | ||
if (/\*$/.test(key)) { | ||
key = key.slice(0, -1) | ||
target = exts | ||
} | ||
if (key in result) { | ||
// strangely, RFC6266 does not mention if disposition parameters | ||
// other than "filename" and "filename*" should be matched case-insensitively | ||
if (/^filename$/i.test(key)) key = key.toLowerCase() | ||
if (key in target) { | ||
throw new ParseError(`duplicated field '${key}'`) | ||
} | ||
result[key] = value | ||
target[key] = value | ||
} | ||
// always prefers "exts" | ||
Object.assign(result, exts) | ||
if (this.chunk.length) { | ||
@@ -164,0 +168,0 @@ throw new ParseError('expect EOF') |
{ | ||
"name": "content-disposition-attachment", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A library to parse \"attachment\"s in Content-Disposition.", | ||
@@ -33,6 +33,6 @@ "main": "index.js", | ||
"devDependencies": { | ||
"ava": "^3.13.0", | ||
"rollup": "^0.55.3", | ||
"standard": "^14.3.4" | ||
"ava": "^3.15.0", | ||
"rollup": "^2.51.2", | ||
"standard": "^16.0.3" | ||
} | ||
} |
8532
161