-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure that find-process does not error out due to a bad regex (#…
…30380) * fix: ensure that find-process does not error out due to a bad regex * add changelog * fix patch * add a test * add comment * update comment * blank * blank
- Loading branch information
1 parent
8a8015b
commit 04c1e8c
Showing
4 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import utils from 'find-process/lib/utils' | ||
import { sinon } from '../../spec_helper' | ||
import { byPid } from '../../../lib/util/find_process' | ||
|
||
describe('lib/util/find_process', function () { | ||
// This is testing the patch for find-process to handle windows processes that have a mixture of carriage returns | ||
it('does not crash in windows with processes that deal with a mixture of carriage returns', async () => { | ||
sinon.stub(process, 'platform').value('win32') | ||
// Create a table that matches what 'Get-CimInstance -className win32_process | select Name,ProcessId,ParentProcessId,CommandLine,ExecutablePath' does in powershell | ||
const process1 = 'Name : abc\r\nProcessId : 123\r\nParentProcessId : 456\r\nCommandLine : "c:\\path\\to\\abc.exe"\r\nExecutablePath : c:\\path\\to\\abc.exe' | ||
const process2 = 'Name : xyz\r\nProcessId : 789\r\nParentProcessId : 1011\r\nCommandLine : "c:\\path\\to\\xyz.exe"\r\nExecutablePath : c:\\path\\to\\xyz.exe' | ||
const process3 = 'Name : def\r\nProcessId : 1213\r\nParentProcessId : 1415\r\nCommandLine : "c:\\path\\to\\def.exe"\r\nExecutablePath : c:\\path\\to\\def.exe' | ||
const process4 = 'Name : ghi\r\nProcessId : 1617\r\nParentProcessId : 1819\r\nCommandLine : "c:\\path\\to\\ghi.exe"\r\nExecutablePath : c:\\path\\to\\ghi.exe' | ||
const process5 = 'Name : jkl\r\nProcessId : 2021\r\nParentProcessId : 2223\r\nCommandLine : "c:\\path\\to\\jkl.exe"\r\nExecutablePath : c:\\path\\to\\jkl.exe' | ||
// Include all of this regex: (\r\n\r\n|\r\n\n|\n\r\n|\n\n) | ||
const returnString = `${process1}\r\n\r\n${process2}\r\n\n${process3}\n\r\n${process4}\n\n${process5}` | ||
|
||
sinon.stub(utils, 'spawn').returns({ | ||
stdout: { | ||
on: (event: string, callback: (data: string) => void) => { | ||
if (event === 'data') { | ||
callback(returnString) | ||
} | ||
}, | ||
}, | ||
on: (event: string, callback: (code: number) => void) => { | ||
if (event === 'close') { | ||
callback(0) | ||
} | ||
}, | ||
}) | ||
|
||
const result1 = await byPid(123) | ||
|
||
expect(result1).to.eql([{ | ||
pid: 123, | ||
ppid: 456, | ||
name: 'abc', | ||
cmd: '"c:\\path\\to\\abc.exe"', | ||
bin: 'c:\\path\\to\\abc.exe', | ||
}]) | ||
|
||
const result2 = await byPid(789) | ||
|
||
expect(result2).to.eql([{ | ||
pid: 789, | ||
ppid: 1011, | ||
name: 'xyz', | ||
cmd: '"c:\\path\\to\\xyz.exe"', | ||
bin: 'c:\\path\\to\\xyz.exe', | ||
}]) | ||
|
||
const result3 = await byPid(1213) | ||
|
||
expect(result3).to.eql([{ | ||
pid: 1213, | ||
ppid: 1415, | ||
name: 'def', | ||
cmd: '"c:\\path\\to\\def.exe"', | ||
bin: 'c:\\path\\to\\def.exe', | ||
}]) | ||
|
||
const result4 = await byPid(1617) | ||
|
||
expect(result4).to.eql([{ | ||
pid: 1617, | ||
ppid: 1819, | ||
name: 'ghi', | ||
cmd: '"c:\\path\\to\\ghi.exe"', | ||
bin: 'c:\\path\\to\\ghi.exe', | ||
}]) | ||
|
||
const result5 = await byPid(2021) | ||
|
||
expect(result5).to.eql([{ | ||
pid: 2021, | ||
ppid: 2223, | ||
name: 'jkl', | ||
cmd: '"c:\\path\\to\\jkl.exe"', | ||
bin: 'c:\\path\\to\\jkl.exe', | ||
}]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/node_modules/find-process/lib/utils.js b/node_modules/find-process/lib/utils.js | ||
index fb7592b..a192426 100644 | ||
--- a/node_modules/find-process/lib/utils.js | ||
+++ b/node_modules/find-process/lib/utils.js | ||
@@ -134,7 +134,7 @@ const utils = { | ||
* @return {Array} | ||
*/ | ||
parseTable (data) { | ||
- const lines = data.split(/(\r\n\r\n|\r\n\n|\n\r\n)|\n\n/).filter(line => { | ||
+ const lines = data.split(/(\r\n\r\n|\r\n\n|\n\r\n|\n\n)/).filter(line => { | ||
return line.trim().length > 0 | ||
}).map((e) => e.split(/(\r\n|\n|\r)/).filter(line => line.trim().length > 0)) | ||
|
04c1e8c
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.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
04c1e8c
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.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
04c1e8c
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.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
04c1e8c
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.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
04c1e8c
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.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally: