mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
fix writing empty string to buffer. closes gh-39
This commit is contained in:
parent
621857746d
commit
c317606b0a
@ -37,7 +37,12 @@ p.addInt16 = function(num) {
|
||||
}
|
||||
|
||||
p.addCString = function(string) {
|
||||
var string = string || "";
|
||||
//just write a 0 for empty or null strings
|
||||
if(!string) {
|
||||
this._ensure(1);
|
||||
this.buffer[this.offset++] = 0;
|
||||
return this;
|
||||
}
|
||||
var len = Buffer.byteLength(string) + 1;
|
||||
this._ensure(len);
|
||||
this.buffer.write(string, this.offset);
|
||||
|
||||
@ -66,6 +66,13 @@ test('cString', function() {
|
||||
var result = subject.addCString().join();
|
||||
assert.equalBuffers(result, [0])
|
||||
})
|
||||
|
||||
test('writes two empty cstrings', function() {
|
||||
var subject = new Writer();
|
||||
var result = subject.addCString("").addCString("").join();
|
||||
assert.equalBuffers(result, [0, 0])
|
||||
})
|
||||
|
||||
|
||||
test('writes non-empty cstring', function() {
|
||||
var subject = new Writer();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user