From 36ba742c9ba81dec352bbce60ed84a0d49fded24 Mon Sep 17 00:00:00 2001 From: alexet Date: Mon, 22 Mar 2021 15:41:07 +0000 Subject: [PATCH] Fix running tests when ms-python is installed. --- extensions/ql-vscode/src/cli.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/src/cli.ts b/extensions/ql-vscode/src/cli.ts index 189f5cca1e6..4cb062cd1ea 100644 --- a/extensions/ql-vscode/src/cli.ts +++ b/extensions/ql-vscode/src/cli.ts @@ -906,6 +906,20 @@ class SplitBuffer { this.buffer += this.separators[0]; // Append a separator to the end to ensure the last line is returned. } + /** + * A version of startsWith that isn't overriden by a broken version of ms-python. + * + * The definition comes from + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith + * which is CC0/public domain + * + * See https://github.com/github/vscode-codeql/issues/802 for more context as to why we need it. + */ + private static startsWith(s: string, searchString: string, position: number): boolean { + const pos = position > 0 ? position | 0 : 0; + return s.substring(pos, pos + searchString.length) === searchString; + } + /** * Extract the next full line from the buffer, if one is available. * @returns The text of the next available full line (without the separator), or `undefined` if no @@ -914,7 +928,7 @@ class SplitBuffer { public getNextLine(): string | undefined { while (this.searchIndex <= (this.buffer.length - this.maxSeparatorLength)) { for (const separator of this.separators) { - if (this.buffer.startsWith(separator, this.searchIndex)) { + if (SplitBuffer.startsWith(this.buffer, separator, this.searchIndex)) { const line = this.buffer.substr(0, this.searchIndex); this.buffer = this.buffer.substr(this.searchIndex + separator.length); this.searchIndex = 0;