Skip to content

Commit 94844ff

Browse files
committed
update comments, remove redundant test
1 parent 95320d5 commit 94844ff

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/__tests__/unit/checks/keywords-urls.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ describe('keywords guardrail', () => {
3333
expect(result.info?.matchedKeywords).toEqual([]);
3434
});
3535

36-
it('should return the correct result', async () => {
37-
const result = await keywordsCheck({}, 'Hello, world!', KeywordsConfig.parse({ keywords: ['hello', 'world'] }));
38-
expect(result.tripwireTriggered).toEqual(true);
39-
});
40-
4136
it('should not match partial words', async () => {
4237
const result = await keywordsCheck({}, 'Hello, world!', KeywordsConfig.parse({ keywords: ['orld'] }));
4338
expect(result.tripwireTriggered).toEqual(false);

src/checks/keywords.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export const keywordsCheck: CheckFn<KeywordsContext, string, KeywordsConfig> = (
5959
);
6060

6161
// \p{L}|\p{N}|_ - any unicode letter, number, or underscore. Alternative to \b
62-
// (?<!\p{L}) - not preceded by a letter
63-
// (?!\p{L}) - not followed by a letter
64-
const patternText = `(?<!\\p{L}|\\p{N}|_)(?:${escapedKeywords.join('|')})(?!\\p{L}|\\p{N}|_)`;
65-
const pattern = new RegExp(patternText, 'giu'); // case-insensitive, global, unicode
62+
// (?<!\\p{L}|\\p{N}|_) - not preceded by a letter
63+
// (?!\\p{L}|\\p{N}|_) - not followed by a letter
64+
const patternText = `(?<!\\p{L}|\\p{N}|_)(?:${escapedKeywords.join('|')})(?!\\p{L}|\\p{N}|_)`;
65+
const pattern = new RegExp(patternText, 'giu'); // case-insensitive, global, unicode
6666

6767
const matches: string[] = [];
6868
let match;

0 commit comments

Comments
 (0)