Skip to content

Commit d909f98

Browse files
alexetadityasharad
andauthored
Fix running tests when ms-python is installed. (#803)
Co-authored-by: Aditya Sharad <[email protected]>
1 parent 8c2db75 commit d909f98

File tree

1 file changed

+15
-1
lines changed
  • extensions/ql-vscode/src

1 file changed

+15
-1
lines changed

extensions/ql-vscode/src/cli.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,20 @@ class SplitBuffer {
906906
this.buffer += this.separators[0]; // Append a separator to the end to ensure the last line is returned.
907907
}
908908

909+
/**
910+
* A version of startsWith that isn't overriden by a broken version of ms-python.
911+
*
912+
* The definition comes from
913+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
914+
* which is CC0/public domain
915+
*
916+
* See https://github.com/github/vscode-codeql/issues/802 for more context as to why we need it.
917+
*/
918+
private static startsWith(s: string, searchString: string, position: number): boolean {
919+
const pos = position > 0 ? position | 0 : 0;
920+
return s.substring(pos, pos + searchString.length) === searchString;
921+
}
922+
909923
/**
910924
* Extract the next full line from the buffer, if one is available.
911925
* @returns The text of the next available full line (without the separator), or `undefined` if no
@@ -914,7 +928,7 @@ class SplitBuffer {
914928
public getNextLine(): string | undefined {
915929
while (this.searchIndex <= (this.buffer.length - this.maxSeparatorLength)) {
916930
for (const separator of this.separators) {
917-
if (this.buffer.startsWith(separator, this.searchIndex)) {
931+
if (SplitBuffer.startsWith(this.buffer, separator, this.searchIndex)) {
918932
const line = this.buffer.substr(0, this.searchIndex);
919933
this.buffer = this.buffer.substr(this.searchIndex + separator.length);
920934
this.searchIndex = 0;

0 commit comments

Comments
 (0)