content-disposition
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -0,1 +1,6 @@ | ||
0.5.2 / 2016-12-08 | ||
================== | ||
* Fix `parse` to accept any linear whitespace character | ||
0.5.1 / 2016-01-17 | ||
@@ -2,0 +7,0 @@ ================== |
70
index.js
@@ -26,3 +26,3 @@ /*! | ||
var encodeUriAttrCharRegExp = /[\x00-\x20"'\(\)*,\/:;<=>?@\[\\\]\{\}\x7f]/g | ||
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g // eslint-disable-line no-control-regex | ||
@@ -33,4 +33,4 @@ /** | ||
var hexEscapeRegExp = /%[0-9A-Fa-f]{2}/ | ||
var hexEscapeReplaceRegExp = /%([0-9A-Fa-f]{2})/g | ||
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/ | ||
var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g | ||
@@ -41,3 +41,3 @@ /** | ||
var nonLatin1RegExp = /[^\x20-\x7e\xa0-\xff]/g | ||
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g | ||
@@ -51,3 +51,3 @@ /** | ||
var qescRegExp = /\\([\u0000-\u007f])/g; | ||
var QESC_REGEXP = /\\([\u0000-\u007f])/g | ||
@@ -58,3 +58,3 @@ /** | ||
var quoteRegExp = /([\\"])/g | ||
var QUOTE_REGEXP = /([\\"])/g | ||
@@ -85,5 +85,5 @@ /** | ||
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g | ||
var textRegExp = /^[\x20-\x7e\x80-\xff]+$/ | ||
var tokenRegExp = /^[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+$/ | ||
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|~-]+$/ | ||
@@ -111,3 +111,3 @@ /** | ||
var extValueRegExp = /^([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!#$&+\-\.^_`|~])+)$/ | ||
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!#$&+.^_`|~-])+)$/ | ||
@@ -127,3 +127,3 @@ /** | ||
var dispositionTypeRegExp = /^([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *(?:$|;)/ | ||
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex | ||
@@ -141,3 +141,3 @@ /** | ||
function contentDisposition(filename, options) { | ||
function contentDisposition (filename, options) { | ||
var opts = options || {} | ||
@@ -164,3 +164,3 @@ | ||
function createparams(filename, fallback) { | ||
function createparams (filename, fallback) { | ||
if (filename === undefined) { | ||
@@ -185,3 +185,3 @@ return | ||
if (typeof fallback === 'string' && nonLatin1RegExp.test(fallback)) { | ||
if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) { | ||
throw new TypeError('fallback must be ISO-8859-1 string') | ||
@@ -194,3 +194,3 @@ } | ||
// determine if name is suitable for quoted string | ||
var isQuotedString = textRegExp.test(name) | ||
var isQuotedString = TEXT_REGEXP.test(name) | ||
@@ -204,3 +204,3 @@ // generate fallback name | ||
// set extended filename parameter | ||
if (hasFallback || !isQuotedString || hexEscapeRegExp.test(name)) { | ||
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) { | ||
params['filename*'] = name | ||
@@ -229,7 +229,7 @@ } | ||
function format(obj) { | ||
function format (obj) { | ||
var parameters = obj.parameters | ||
var type = obj.type | ||
if (!type || typeof type !== 'string' || !tokenRegExp.test(type)) { | ||
if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) { | ||
throw new TypeError('invalid type') | ||
@@ -268,4 +268,4 @@ } | ||
function decodefield(str) { | ||
var match = extValueRegExp.exec(str) | ||
function decodefield (str) { | ||
var match = EXT_VALUE_REGEXP.exec(str) | ||
@@ -281,3 +281,3 @@ if (!match) { | ||
// to binary string | ||
var binary = encoded.replace(hexEscapeReplaceRegExp, pdecode) | ||
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode) | ||
@@ -306,5 +306,5 @@ switch (charset) { | ||
function getlatin1(val) { | ||
function getlatin1 (val) { | ||
// simple Unicode -> ISO-8859-1 transformation | ||
return String(val).replace(nonLatin1RegExp, '?') | ||
return String(val).replace(NON_LATIN1_REGEXP, '?') | ||
} | ||
@@ -320,3 +320,3 @@ | ||
function parse(string) { | ||
function parse (string) { | ||
if (!string || typeof string !== 'string') { | ||
@@ -326,3 +326,3 @@ throw new TypeError('argument string is required') | ||
var match = dispositionTypeRegExp.exec(string) | ||
var match = DISPOSITION_TYPE_REGEXP.exec(string) | ||
@@ -343,3 +343,3 @@ if (!match) { | ||
// calculate index to start at | ||
index = paramRegExp.lastIndex = match[0].substr(-1) === ';' | ||
index = PARAM_REGEXP.lastIndex = match[0].substr(-1) === ';' | ||
? index - 1 | ||
@@ -349,3 +349,3 @@ : index | ||
// match parameters | ||
while (match = paramRegExp.exec(string)) { | ||
while ((match = PARAM_REGEXP.exec(string))) { | ||
if (match.index !== index) { | ||
@@ -383,3 +383,3 @@ throw new TypeError('invalid parameter format') | ||
.substr(1, value.length - 2) | ||
.replace(qescRegExp, '$1') | ||
.replace(QESC_REGEXP, '$1') | ||
} | ||
@@ -406,3 +406,3 @@ | ||
function pdecode(str, hex) { | ||
function pdecode (str, hex) { | ||
return String.fromCharCode(parseInt(hex, 16)) | ||
@@ -419,3 +419,3 @@ } | ||
function pencode(char) { | ||
function pencode (char) { | ||
var hex = String(char) | ||
@@ -438,6 +438,6 @@ .charCodeAt(0) | ||
function qstring(val) { | ||
function qstring (val) { | ||
var str = String(val) | ||
return '"' + str.replace(quoteRegExp, '\\$1') + '"' | ||
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"' | ||
} | ||
@@ -453,3 +453,3 @@ | ||
function ustring(val) { | ||
function ustring (val) { | ||
var str = String(val) | ||
@@ -459,3 +459,3 @@ | ||
var encoded = encodeURIComponent(str) | ||
.replace(encodeUriAttrCharRegExp, pencode) | ||
.replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode) | ||
@@ -469,5 +469,5 @@ return 'UTF-8\'\'' + encoded | ||
function ContentDisposition(type, parameters) { | ||
function ContentDisposition (type, parameters) { | ||
this.type = type | ||
this.parameters = parameters | ||
} |
{ | ||
"name": "content-disposition", | ||
"description": "Create and parse Content-Disposition header", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"contributors": [ | ||
@@ -17,3 +17,7 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>" | ||
"devDependencies": { | ||
"istanbul": "0.4.2", | ||
"eslint": "3.11.1", | ||
"eslint-config-standard": "6.2.1", | ||
"eslint-plugin-promise": "3.3.0", | ||
"eslint-plugin-standard": "2.0.1", | ||
"istanbul": "0.4.5", | ||
"mocha": "1.21.5" | ||
@@ -31,2 +35,3 @@ }, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "mocha --reporter spec --bail --check-leaks test/", | ||
@@ -33,0 +38,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", |
@@ -135,3 +135,3 @@ # content-disposition | ||
[node-version-image]: https://img.shields.io/node/v/content-disposition.svg?style=flat | ||
[node-version-url]: http://nodejs.org/download/ | ||
[node-version-url]: https://nodejs.org/en/download | ||
[travis-image]: https://img.shields.io/travis/jshttp/content-disposition.svg?style=flat | ||
@@ -138,0 +138,0 @@ [travis-url]: https://travis-ci.org/jshttp/content-disposition |
18530
6