Skip to content

Conversation

@AlexanderSchicktanz
Copy link
Collaborator

fix #2516

hansegucker
hansegucker previously approved these changes Oct 27, 2025
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add test cases where the "trigger word" contains multiple words? because your function actually allows this :)

Comment on lines +11 to +15
let j;
for (j = 0; j < sub.length; j++) {
if (arr[i + j] !== sub[j]) break;
}
if (j == sub.length) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be slightly nicer if you create another helper function arrayEquals(a: string[]. b: string[]): bool :)

Bonus points: Can you remove the string type and make a generic function instead? Take a look at our utils.ts file for examples, or ask if you need some input :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that this change would make a nice improvement to the current implementation

janno42
janno42 previously approved these changes Oct 27, 2025
Copy link
Member

@janno42 janno42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ functionality tested

Comment on lines +21 to +22
const words = text.split(" ");
const triggerWords = triggerString.split(" ");
Copy link
Member

@niklasmohrin niklasmohrin Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting by a single space character means that we don't match if users accidentally put two spaces. We should split by any amount of whitespace (like what happens in Python when using str.split without passing any argument)

function matchesTriggerString(text: string, triggerString: string): boolean {
const words = text.split(" ");
const triggerWords = triggerString.split(" ");
return containsSubArray(words, triggerWords);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably means that if users write something like "see above." at the end of a sentence we will not show a warning because the dot is included in the last word.

Doing this completely correct seems tough, unless we at some point change the UI so that staff users can enter arbitrary regexes as trigger words. What do you think we should aim for in this PR @janno42 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could first preprocess (before splitting) by regex-replacing all non-word characters with a delimiter, then splitting on the delimiter. Then, punctuation, arbitrarily weird (repeated) whitespace and other non-printable characters would not be an issue.

Comment on lines +11 to +15
let j;
for (j = 0; j < sub.length; j++) {
if (arr[i + j] !== sub[j]) break;
}
if (j == sub.length) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that this change would make a nice improvement to the current implementation

@richardebeling richardebeling removed their request for review November 3, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Regard word limits in text answer warnings

6 participants