From 4c5ed7e3c8ef746bc9dbb812eaa2f79fd1e0456f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Weinand?= Date: Wed, 11 Apr 2018 12:51:10 +0200 Subject: [PATCH] be more resilent when parsing RFC 2822 header in DAP --- .../workbench/parts/debug/node/debugAdapter.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/parts/debug/node/debugAdapter.ts b/src/vs/workbench/parts/debug/node/debugAdapter.ts index 9d6c1456e80..943bb658fb9 100644 --- a/src/vs/workbench/parts/debug/node/debugAdapter.ts +++ b/src/vs/workbench/parts/debug/node/debugAdapter.ts @@ -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; @@ -191,13 +193,12 @@ 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]); } @@ -205,17 +206,6 @@ export abstract class StreamDebugAdapter extends AbstractDebugAdapter { 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; } -- GitLab