Comparing version 1.1.1 to 1.2.0
@@ -111,2 +111,10 @@ /*global unescape*/ | ||
function quoteParameterIfNecessary(value) { | ||
if (/[()<>@,;:\\"\/[\]?=]/.test(value)) { | ||
return '"' + value.replace(/[\\"]/g, '\\$&') + '"'; | ||
} else { | ||
return value; | ||
} | ||
} | ||
rfc2231.encodeAndFoldParameters = function (decodedParameters, maxFragmentLength, forceUtf8) { | ||
@@ -150,3 +158,3 @@ var encodedParameters = {}; | ||
} | ||
encodedParameters[parameterName + '*' + fragmentNum + (isEncoded ? '*' : '')] = isEncoded ? fragment : '"' + fragment.replace(/[\\"]/g, '\\$&') + '"'; | ||
encodedParameters[parameterName + '*' + fragmentNum + (isEncoded ? '*' : '')] = quoteParameterIfNecessary(fragment); | ||
@@ -157,3 +165,3 @@ pos += fragment.length; | ||
} else { | ||
encodedParameters[parameterName + (isEncoded ? '*' : '')] = isEncoded ? value : '"' + value.replace(/[\\"]/g, '\\$&') + '"'; | ||
encodedParameters[parameterName + (isEncoded ? '*' : '')] = quoteParameterIfNecessary(value); | ||
} | ||
@@ -160,0 +168,0 @@ }); |
{ | ||
"name": "rfc2231", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Encode and decode rfc2231/rfc5987", | ||
@@ -5,0 +5,0 @@ "main": "lib/rfc2231.js", |
@@ -20,2 +20,6 @@ /*global describe, it*/ | ||
it('should only quote parameter values that contain tspecials (rfc2045)', function () { | ||
expect({bar: 'baz', foo: '>', quotes: '""'}, 'to encode to', {bar: 'baz', foo: '">"', quotes: '"\\"\\""'}); | ||
}); | ||
it('Single-line us-ascii (from RFC2231)', function () { | ||
@@ -95,3 +99,3 @@ expect({ | ||
}, 'to encode back and forth to', { | ||
foo: '"aa"' | ||
foo: 'aa' | ||
}); | ||
@@ -104,4 +108,4 @@ }); | ||
}, 'to encode back and forth to', { | ||
'foo*0': '"012345678901234567890123456789012345678901234567890123456789"', | ||
'foo*1': '"0123456789"' | ||
'foo*0': '012345678901234567890123456789012345678901234567890123456789', | ||
'foo*1': '0123456789' | ||
}); | ||
@@ -108,0 +112,0 @@ }); |
20438
279