Skip to content

Commit 34b42ed

Browse files
authored
fix: handle ^ and $ in rules (#684)
1 parent ca6fafd commit 34b42ed

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/util/classes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ export function matchString(str: string, categories: Category[] | null): Categor
214214
const regexes: [Category, RegExp][] = categories
215215
.filter(c => c.rule.type == 'regex')
216216
.map(c => {
217-
const re = RegExp(c.rule.regex, c.rule.ignore_case ? 'i' : '');
217+
// using 'm' flag to make `$` and `^` in rules work
218+
const re = RegExp(c.rule.regex, (c.rule.ignore_case ? 'i' : '') + 'm');
218219
return [c, re];
219220
});
220221

@@ -227,6 +228,7 @@ export function matchString(str: string, categories: Category[] | null): Categor
227228
return null;
228229
}
229230

231+
// this is used only in tests
230232
export function classifyEvents(events: IEvent[], categories: Category[]): IEvent[] {
231233
// Compile regexes
232234
const regexes: [Category, RegExp][] = categories

src/util/color.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ export function getTitleAttr(bucket: { type?: string }, e: IEvent) {
129129

130130
export function getCategoryColorFromEvent(bucket: IBucket, e: IEvent) {
131131
if (bucket.type == 'currentwindow') {
132-
// NOTE: this will not work/break category rules which reference `$` or `^`
133-
return getCategoryColorFromString(e.data.app + ' ' + e.data.title);
132+
// using linebreak and "m" regex flag to make `$` and `^` work
133+
return getCategoryColorFromString(e.data.app + '\n' + e.data.title);
134134
} else if (bucket.type == 'web.tab.current') {
135-
// NOTE: same as above
136-
return getCategoryColorFromString(e.data.title + ' ' + e.data.url);
135+
// same as above
136+
return getCategoryColorFromString(e.data.title + '\n' + e.data.url);
137137
} else if (bucket.type == 'afkstatus') {
138138
return getColorFromString(e.data.status);
139139
} else if (bucket.type?.startsWith('app.editor')) {

0 commit comments

Comments
 (0)