File tree Expand file tree Collapse file tree 4 files changed +18
-12
lines changed
Expand file tree Collapse file tree 4 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ p.startup = function(config) {
7474
7575p . password = function ( password ) {
7676 //0x70 = 'p'
77- this . send ( 0x70 , Buffer ( password + '\0' , this . encoding ) ) ;
77+ this . send ( 0x70 , new Writer ( ) . addCString ( password ) . join ( ) ) ;
7878} ;
7979
8080p . send = function ( code , bodyBuffer ) {
@@ -97,7 +97,7 @@ p.end = function() {
9797
9898p . query = function ( text ) {
9999 //0x51 = Q
100- this . send ( 0x51 , new Buffer ( text + '\0' , this . encoding ) ) ;
100+ this . send ( 0x51 , new Writer ( ) . addCString ( text ) . join ( ) ) ;
101101} ;
102102
103103p . parse = function ( query ) {
@@ -181,9 +181,7 @@ p.end = function() {
181181} ;
182182
183183p . describe = function ( msg ) {
184- var str = msg . type + ( msg . name || "" ) + '\0' ;
185- var buffer = Buffer ( str , this . encoding ) ;
186- this . send ( 0x44 , buffer ) ;
184+ this . send ( 0x44 , new Writer ( ) . addCString ( msg . type + ( msg . name || '' ) ) . join ( ) ) ;
187185} ;
188186
189187//parsing methods
Original file line number Diff line number Diff line change @@ -32,7 +32,11 @@ p.addInt32 = function(val, first) {
3232} ;
3333
3434p . addCString = function ( val ) {
35- return this . add ( Buffer ( val + '\0' , 'utf8' ) ) ;
35+ var len = Buffer . byteLength ( val ) ;
36+ var buffer = new Buffer ( len + 1 ) ;
37+ buffer . write ( val ) ;
38+ buffer [ len ] = 0 ;
39+ return this . add ( buffer ) ;
3640} ;
3741
3842p . addChar = function ( char , first ) {
Original file line number Diff line number Diff line change @@ -27,8 +27,12 @@ p.addInt32 = function(val, first) {
2727 ] ) , first ) ;
2828} ;
2929
30- p . addCString = function ( val ) {
31- return this . add ( Buffer ( val + '\0' , 'utf8' ) ) ;
30+ p . addCString = function ( val , front ) {
31+ var len = Buffer . byteLength ( val ) ;
32+ var buffer = new Buffer ( len + 1 ) ;
33+ buffer . write ( val ) ;
34+ buffer [ len ] = 0 ;
35+ return this . add ( buffer , front ) ;
3236} ;
3337
3438p . addChar = function ( char , first ) {
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ var oneFieldBuf = new BufferList()
5757 . addCString ( 'test' )
5858 . join ( true , 'D' ) ;
5959
60- var oneFieldBuf = buffers . dataRow ( [ 'test\0 ' ] ) ;
60+ var oneFieldBuf = buffers . dataRow ( [ 'test' ] ) ;
6161
6262
6363var expectedAuthenticationOkayMessage = {
@@ -67,9 +67,9 @@ var expectedAuthenticationOkayMessage = {
6767
6868var expectedParameterStatusMessage = {
6969 name : 'parameterStatus' ,
70- length : 25 ,
7170 parameterName : 'client_encoding' ,
72- parameterValue : 'UTF8'
71+ parameterValue : 'UTF8' ,
72+ length : 25
7373} ;
7474
7575var expectedBackendKeyDataMessage = {
@@ -246,7 +246,7 @@ test('Connection', function() {
246246 } ) ;
247247
248248 test ( 'field is correct' , function ( ) {
249- assert . equal ( message . fields [ 0 ] , 'test\0 ' ) ;
249+ assert . equal ( message . fields [ 0 ] , 'test' ) ;
250250 } ) ;
251251 } ) ;
252252
You can’t perform that action at this time.
0 commit comments