From e6255c3935fbbbcaeddcd0cb4ab295e9795acc2b Mon Sep 17 00:00:00 2001 From: Adrienne Walker Date: Thu, 30 Nov 2023 16:15:09 -0800 Subject: [PATCH] raidboss: support bareword keys in timeline netregex (#5967) Rather than eval (which is probably TOO lenient) switch to using json5 instead of json parsing. This is a followup to a TODO from #5939. --- ui/raidboss/data/00-misc/test.txt | 3 +++ ui/raidboss/timeline_parser.ts | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/raidboss/data/00-misc/test.txt b/ui/raidboss/data/00-misc/test.txt index 1127898107..fdaa00f1cd 100644 --- a/ui/raidboss/data/00-misc/test.txt +++ b/ui/raidboss/data/00-misc/test.txt @@ -18,7 +18,10 @@ hideall "--sync--" 0 "--Reset--" sync /You bid farewell to the striking dummy/ window 10000 jump 0 +# two examples with different quoting which should both be supported +0 "--sync--" GameLog { line: 'testNetRegexTimeline' } window 100000,100000 0 "--sync--" GameLog { "line": "testNetRegexTimeline" } window 100000,100000 + 0 "--sync--" sync /:Engage!/ window 100000,100000 0 "--sync--" sync /:You bow courteously to the striking dummy/ window 0,1 3 "Almagest" diff --git a/ui/raidboss/timeline_parser.ts b/ui/raidboss/timeline_parser.ts index 609246d2a5..912e69a673 100644 --- a/ui/raidboss/timeline_parser.ts +++ b/ui/raidboss/timeline_parser.ts @@ -1,3 +1,5 @@ +import JSON5 from 'json5'; + import { Lang } from '../../resources/languages'; import logDefinitions, { LogDefinitionTypes } from '../../resources/netlog_defs'; import { buildNetRegexForTrigger } from '../../resources/netregexes'; @@ -485,9 +487,8 @@ export class TimelineParser { let params: unknown; try { - // TODO: Use `exec` => `JSON.stringify` => `JSON.parse` instead? - // See https://github.com/quisquous/cactbot/pull/5939#issuecomment-1830484703 - params = JSON.parse(syncCommand.netRegex); + // Use json5 here to support bareword keys and different quoting styles. + params = JSON5.parse(syncCommand.netRegex); } catch (e) { this.errors.push({ lineNumber: lineNumber,