Comparing version 1.2.0 to 1.2.1
@@ -137,2 +137,14 @@ /*global unescape*/ | ||
Message.prototype.hasEmptyBody = function () { | ||
if (typeof this.body === 'string') { | ||
return this.body.length === 0; | ||
} else if (typeof Buffer === 'function' && Buffer.isBuffer(this.body)) { | ||
return this.body.length === 0; | ||
} else if (this.body && typeof this.body === 'object') { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}; | ||
function isTextualContentType(contentType) { | ||
@@ -139,0 +151,0 @@ if (typeof contentType === 'string') { |
{ | ||
"name": "messy", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Object model for HTTP and RFC822 messages", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -174,2 +174,32 @@ /*global describe, it*/ | ||
}); | ||
describe('#hasEmptyBody', function () { | ||
it('should consider a zero length Buffer to be an empty body', function () { | ||
expect(new Message({body: new Buffer([])}).hasEmptyBody(), 'to be true'); | ||
}); | ||
it('should consider a non-zero length Buffer not to be an empty body', function () { | ||
expect(new Message({body: new Buffer([123])}).hasEmptyBody(), 'to be false'); | ||
}); | ||
it('should consider the empty string to be an empty body', function () { | ||
expect(new Message({body: ''}).hasEmptyBody(), 'to be true'); | ||
}); | ||
it('should consider a non-empty string not to be an empty body', function () { | ||
expect(new Message({body: 'foo'}).hasEmptyBody(), 'to be false'); | ||
}); | ||
it('should consider undefined to be an empty body', function () { | ||
expect(new Message({body: undefined}).hasEmptyBody(), 'to be true'); | ||
}); | ||
it('should consider an absent body to be empty', function () { | ||
expect(new Message().hasEmptyBody(), 'to be true'); | ||
}); | ||
it('should consider an empty Object to be a non-empty body', function () { | ||
expect(new Message({body: {}}).hasEmptyBody(), 'to be false'); | ||
}); | ||
}); | ||
}); |
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
78834
1707