Skip to content

Commit

Permalink
be more resilent when parsing RFC 2822 header in DAP
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Apr 11, 2018
1 parent c28e9b1 commit 4c5ed7e
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/vs/workbench/parts/debug/node/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export abstract class AbstractDebugAdapter implements debug.IDebugAdapter {
export abstract class StreamDebugAdapter extends AbstractDebugAdapter {

private static readonly TWO_CRLF = '\r\n\r\n';
private static readonly HEADER_LINESEPARATOR = /\r?\n/; // allow for non-RFC 2822 conforming line separators
private static readonly HEADER_FIELDSEPARATOR = /: */;

private outputStream: stream.Writable;
private rawData: Buffer;
Expand Down Expand Up @@ -191,31 +193,19 @@ export abstract class StreamDebugAdapter extends AbstractDebugAdapter {
continue; // there may be more complete messages to process
}
} else {
/*
const idx = this.rawData.indexOf(StreamDebugAdapter.TWO_CRLF);
if (idx !== -1) {
const header = this.rawData.toString('utf8', 0, idx);
const lines = header.split('\r\n');
const lines = header.split(StreamDebugAdapter.HEADER_LINESEPARATOR);
for (const h of lines) {
const kvPair = h.split(/: +/);
const kvPair = h.split(StreamDebugAdapter.HEADER_FIELDSEPARATOR);
if (kvPair[0] === 'Content-Length') {
this.contentLength = Number(kvPair[1]);
}
}
this.rawData = this.rawData.slice(idx + StreamDebugAdapter.TWO_CRLF.length);
continue;
}
*/
const s = this.rawData.toString('utf8', 0, this.rawData.length);
const idx = s.indexOf(StreamDebugAdapter.TWO_CRLF);
if (idx !== -1) {
const match = /Content-Length: (\d+)/.exec(s);
if (match && match[1]) {
this.contentLength = Number(match[1]);
this.rawData = this.rawData.slice(idx + StreamDebugAdapter.TWO_CRLF.length);
continue; // try to handle a complete message
}
}
}
break;
}
Expand Down

0 comments on commit 4c5ed7e

Please sign in to comment.