Skip to content

Commit 0f7b596

Browse files
committed
No trailing spaces in hex strings
1 parent 0f2a80c commit 0f7b596

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

src/v1/internal/buf.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,17 @@ class BaseBuffer
346346
* Get string representation of buffer.
347347
* @return {string} Buffer as a string
348348
*/
349-
toHex () {
350-
// TODO something like StringBuilder?
351-
let out = "";
349+
toHex() {
350+
let out = '';
352351
for (let i = 0; i < this.length; i++) {
353352
let hexByte = this.getUInt8(i).toString(16);
354-
if( hexByte.length == 1 ) {
355-
hexByte = "0" + hexByte;
353+
if (hexByte.length == 1) {
354+
hexByte = '0' + hexByte;
355+
}
356+
out += hexByte;
357+
if (i !== this.length - 1) {
358+
out += ' ';
356359
}
357-
out += hexByte + " "
358360
}
359361
return out;
360362
}

src/v1/internal/ch-dummy.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {CombinedBuffer} from './buf';
2222
const observer = {
2323
instance: null,
2424
updateInstance: (instance) => {
25-
observer.instance = instance
25+
observer.instance = instance;
2626
}
2727
};
2828

@@ -40,21 +40,24 @@ class DummyChannel {
4040
return false;
4141
}
4242

43-
write( buf ) {
43+
write(buf) {
4444
this.written.push(buf);
4545
observer.updateInstance(this);
4646
}
4747

4848
toHex() {
49-
var out = "";
50-
for( var i=0; i<this.written.length; i++ ) {
49+
let out = '';
50+
for (let i = 0; i < this.written.length; i++) {
5151
out += this.written[i].toHex();
52+
if (i !== this.written.length - 1) {
53+
out += ' ';
54+
}
5255
}
5356
return out;
5457
}
5558

56-
toBuffer () {
57-
return new CombinedBuffer( this.written );
59+
toBuffer() {
60+
return new CombinedBuffer(this.written);
5861
}
5962

6063
close(cb) {
@@ -71,4 +74,4 @@ class DummyChannel {
7174

7275
const channel = DummyChannel;
7376

74-
export { channel, observer }
77+
export {channel, observer};

test/internal/buf.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('buffers', () => {
3737

3838
// Then
3939
expect(str).toContain('( position=4 )\n 01 08 0f 7f');
40-
expect(hex).toBe('01 08 0f 7f ');
40+
expect(hex).toBe('01 08 0f 7f');
4141
});
4242

4343
it('should read and write 8-bit unsigned integers', () => {
@@ -139,7 +139,7 @@ describe('buffers', () => {
139139
// When
140140
const hex = b.toHex();
141141
// Then
142-
expect(hex).toBe('92 81 61 81 62 ');
142+
expect(hex).toBe('92 81 61 81 62');
143143
});
144144

145145
it('should decode list correctly', () => {

test/internal/chunking.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Chunker', function() {
3535
chunker.flush();
3636

3737
// Then
38-
expect( ch.toHex() ).toBe("00 08 00 00 00 01 00 00 00 02 ");
38+
expect(ch.toHex()).toBe('00 08 00 00 00 01 00 00 00 02');
3939
});
4040
it('should chunk blobs larger than the output buffer', function() {
4141
// Given
@@ -47,7 +47,7 @@ describe('Chunker', function() {
4747
chunker.flush();
4848

4949
// Then
50-
expect( ch.toHex() ).toBe("00 02 01 02 00 02 03 04 00 02 05 06 ");
50+
expect(ch.toHex()).toBe('00 02 01 02 00 02 03 04 00 02 05 06');
5151
});
5252
it('should include message boundaries', function() {
5353
// Given
@@ -61,7 +61,7 @@ describe('Chunker', function() {
6161
chunker.flush();
6262

6363
// Then
64-
expect( ch.toHex() ).toBe("00 04 00 00 00 01 00 00 00 04 00 00 00 02 ");
64+
expect(ch.toHex()).toBe('00 04 00 00 00 01 00 00 00 04 00 00 00 02');
6565
});
6666
});
6767

@@ -83,7 +83,7 @@ describe('Dechunker', function() {
8383

8484
// Then
8585
expect( messages.length ).toBe( 1 );
86-
expect( messages[0].toHex() ).toBe( "00 01 00 02 00 03 " );
86+
expect(messages[0].toHex()).toBe('00 01 00 02 00 03');
8787
});
8888

8989
it('should handle message split at any point', function() {
@@ -117,7 +117,7 @@ describe('Dechunker', function() {
117117

118118
// Then, the output should be correct
119119
expect( messages.length ).toBe( 1 );
120-
expect( messages[0].toHex() ).toBe( "01 00 02 00 00 00 03 04 00 00 00 05 " );
120+
expect(messages[0].toHex()).toBe('01 00 02 00 00 00 03 04 00 00 00 05');
121121
};
122122
});
123123
});

test/internal/connection.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Connection', () => {
113113
const protocolVersion2 = '00 00 00 02';
114114
const protocolVersion1 = '00 00 00 01';
115115
const noProtocolVersion = '00 00 00 00';
116-
expect(observer.instance.toHex()).toBe(`${boltMagicPreamble} ${protocolVersion3} ${protocolVersion2} ${protocolVersion1} ${noProtocolVersion} `);
116+
expect(observer.instance.toHex()).toBe(`${boltMagicPreamble} ${protocolVersion3} ${protocolVersion2} ${protocolVersion1} ${noProtocolVersion}`);
117117
});
118118

119119
it('should provide error message when connecting to http-port', done => {

test/internal/protocol-handshaker.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('ProtocolHandshaker', () => {
4242
const protocolVersion1 = '00 00 00 01';
4343
const noProtocolVersion = '00 00 00 00';
4444

45-
expect(writtenBuffers[0].toHex()).toEqual(`${boltMagicPreamble} ${protocolVersion3} ${protocolVersion2} ${protocolVersion1} ${noProtocolVersion} `);
45+
expect(writtenBuffers[0].toHex()).toEqual(`${boltMagicPreamble} ${protocolVersion3} ${protocolVersion2} ${protocolVersion1} ${noProtocolVersion}`);
4646
});
4747

4848
it('should create protocol with valid version', () => {

0 commit comments

Comments
 (0)