Skip to content

Commit eb41039

Browse files
committed
🔧 update: improve condition evaluation by refining keyword extraction
1 parent 073d09a commit eb41039

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

packages/shield/src/matcher.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ function evaluateCondition(
144144
if (lc.includes('arguments containing')) {
145145
const argsStr = JSON.stringify(event.toolArgs ?? {}).toLowerCase();
146146
// Extract keywords from parenthetical list
147-
const parenMatch = condition.match(/\(([^)]+)\)/);
148-
if (parenMatch) {
149-
const keywords = parenMatch[1].split(',').map((k) => k.trim().toLowerCase());
147+
const openIdx = condition.indexOf('(');
148+
const closeIdx = openIdx >= 0 ? condition.indexOf(')', openIdx + 1) : -1;
149+
if (openIdx >= 0 && closeIdx > openIdx) {
150+
const keywords = condition.slice(openIdx + 1, closeIdx).split(',').map((k) => k.trim().toLowerCase());
150151
for (const keyword of keywords) {
151152
if (keyword && argsStr.includes(keyword)) {
152153
return { matchedOn: 'tool.args', matchValue: keyword };
@@ -204,7 +205,7 @@ function evaluateCondition(
204205

205206
// Handle OR operator
206207
if (expected.includes(' or ')) {
207-
const alternatives = expected.split(/\s+or\s+/i);
208+
const alternatives = expected.split(' or ');
208209
for (const alt of alternatives) {
209210
const trimmed = alt.trim();
210211
if (eventDomain === trimmed || eventDomain.endsWith(`.${trimmed}`)) {

0 commit comments

Comments
 (0)