From 38048570ea1f57a3da59988da78238204af7ada6 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 26 Mar 2024 17:48:54 +0300 Subject: [PATCH] fix: ppid search should use strict equal cond fixes: https://github.com/UmbraEngineering/ps/issues/5 --- src/main/ts/ps.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/ts/ps.ts b/src/main/ts/ps.ts index 6e401e5..3f1924b 100644 --- a/src/main/ts/ps.ts +++ b/src/main/ts/ps.ts @@ -91,15 +91,14 @@ export const parseProcessList = (output: string, query: TPsLookupQuery = {}) => const processList = parseGrid(output.trim()) const pidList= (query.pid === undefined ? [] : [query.pid].flat(1)).map(v => v + '') - const filter = (['command', 'arguments', 'ppid'] as Array) - .reduce((m, k) => { - const param = query[k] - if (param) m[k] = new RegExp(param + '', 'i') - return m - }, {} as Record) + const filters: Array<(p: TPsLookupEntry) => boolean> = [ + p => query.command ? new RegExp(query.command, 'i').test(p.command) : true, + p => query.arguments ? new RegExp(query.arguments, 'i').test(p.arguments.join(' ')) : true, + p => query.ppid ? query.ppid + '' === p.ppid : true + ] return processList.filter(p => - (pidList.length === 0 || pidList.includes(p.pid)) && Object.keys(filter).every((type) => filter[type as TFilterKeys].test(p[type as keyof TPsLookupEntry] + '')) + (pidList.length === 0 || pidList.includes(p.pid)) && filters.every(f => f(p)) ) }