Comparing version 3.1.1 to 3.1.2
@@ -117,3 +117,3 @@ var foldHeaderLine = require('./foldHeaderLine'), | ||
if (this.valuesByName[headerNameLowerCase]) { | ||
Array.prototype.push.apply(this.valuesByName[headerNameLowerCase], value) | ||
Array.prototype.push.apply(this.valuesByName[headerNameLowerCase], value); | ||
} else { | ||
@@ -170,3 +170,7 @@ this.valuesByName[headerNameLowerCase] = [].concat(value); | ||
if (Array.isArray(valueOrValues)) { | ||
this.valuesByName[headerNameLowerCase] = valueOrValues.map(String); | ||
if (valueOrValues.length === 0) { | ||
delete this.valuesByName[headerNameLowerCase]; | ||
} else { | ||
this.valuesByName[headerNameLowerCase] = valueOrValues.map(String); | ||
} | ||
} else { | ||
@@ -173,0 +177,0 @@ (this.valuesByName[headerNameLowerCase] = this.valuesByName[headerNameLowerCase] || []).push(String(valueOrValues)); |
{ | ||
"name": "messy", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Object model for HTTP and RFC822 messages", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -126,2 +126,26 @@ /*global describe, it*/ | ||
}); | ||
describe('#set', function () { | ||
it('should preserve existing values when adding a string value', function () { | ||
var headers = new Headers({foo: 'bar'}); | ||
expect(headers.toString(), 'to equal', 'Foo: bar\r\n'); | ||
headers.set('foo', 'quux'); | ||
expect(headers.toString(), 'to equal', 'Foo: bar\r\nFoo: quux\r\n'); | ||
}); | ||
it('should remove all existing values when passed an empty array', function () { | ||
var headers = new Headers({foo: 'bar'}); | ||
expect(headers.toString(), 'to equal', 'Foo: bar\r\n'); | ||
headers.set('foo', []); | ||
expect(headers.valuesByName.foo, 'to be undefined'); | ||
expect(headers.toString(), 'to equal', ''); | ||
}); | ||
it('should replace existing values when passed an array of strings', function () { | ||
var headers = new Headers({foo: 'bar'}); | ||
expect(headers.toString(), 'to equal', 'Foo: bar\r\n'); | ||
headers.set('foo', ['hey']); | ||
expect(headers.toString(), 'to equal', 'Foo: hey\r\n'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82388
1770