-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debugger: fix debugger failure when passing commands with non-latin symbols #11841
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ function Client(agent, socket) { | |
// Parse incoming data | ||
this.state = 'headers'; | ||
this.headers = {}; | ||
this.buffer = ''; | ||
this.buffer = new Buffer(0); | ||
socket.pipe(this); | ||
|
||
this.on('data', this.onCommand); | ||
|
@@ -117,39 +117,40 @@ Client.prototype.destroy = function destroy(msg) { | |
Client.prototype._transform = function _transform(data, enc, cb) { | ||
cb(); | ||
|
||
this.buffer += data; | ||
this.buffer = Buffer.concat([this.buffer, data]); | ||
|
||
while (true) { | ||
if (this.state === 'headers') { | ||
// Not enough data | ||
if (!this.buffer.includes('\r\n')) | ||
break; | ||
|
||
if (this.buffer.startsWith('\r\n')) { | ||
var bufString = this.buffer.toString('utf8'); | ||
if (bufString.startsWith('\r\n')) { | ||
this.buffer = this.buffer.slice(2); | ||
this.state = 'body'; | ||
continue; | ||
} | ||
|
||
// Match: | ||
// Header-name: header-value\r\n | ||
var match = this.buffer.match(/^([^:\s\r\n]+)\s*:\s*([^\s\r\n]+)\r\n/); | ||
var match = bufString.match(/^([^:\s\r\n]+)\s*:\s*([^\s\r\n]+)\r\n/); | ||
if (!match) | ||
return this.destroy('Expected header, but failed to parse it'); | ||
|
||
this.headers[match[1].toLowerCase()] = match[2]; | ||
|
||
this.buffer = this.buffer.slice(match[0].length); | ||
this.buffer = this.buffer.slice(Buffer.byteLength(match[0], 'utf8')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will likely be a bit of a performance hit on this given the multiple utf8 conversions involved on chunks of the buffer (the toString above, the byteLength call here). We should benchmark this change to see how much of a hit this causes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
var len = this.headers['content-length']; | ||
if (len === undefined) | ||
return this.destroy('Expected content-length'); | ||
|
||
len = len | 0; | ||
if (Buffer.byteLength(this.buffer) < len) | ||
if (Buffer.byteLength(this.buffer, 'utf8') < len) | ||
break; | ||
|
||
this.push(new Command(this.headers, this.buffer.slice(0, len))); | ||
this.push(new Command(this.headers, this.buffer.slice(0, len).toString('utf8'))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long line. Can you run |
||
this.state = 'headers'; | ||
this.buffer = this.buffer.slice(len); | ||
this.headers = {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use
Buffer.alloc(0)
here?