diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-03-16 15:32:37 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-06-06 03:06:43 +0000 |
| commit | a4dd1c43348deacb200e92ff41a1efd9684b345e (patch) | |
| tree | 5dd17e0218c8ee2460862ec71a50cd5fd7fb30ca | |
| parent | 2c08ae7470f7d057b69e9047c34caab1abbe205d (diff) | |
iniParse: fix case mangling and double regex
INI parser normalized everything in INI (except for "showname" value)
and recomputed regex match twice for parameters and sections.
| -rw-r--r-- | webAO/iniParse.ts | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/webAO/iniParse.ts b/webAO/iniParse.ts index ca84c353..74bd7641 100644 --- a/webAO/iniParse.ts +++ b/webAO/iniParse.ts @@ -9,10 +9,6 @@ const regexPatterns = { comment: /^\s*;.*$/, }; -const valueHandler = (matchKey: string, matchValue: string): string => { - return matchKey === "showname" ? matchValue : matchValue.toLowerCase(); -}; - const lineFilter = (value: string): boolean => { const isEmpty: boolean = value.length === 0; const isComment: boolean = regexPatterns.comment.test(value); @@ -31,24 +27,16 @@ const iniParse = (data: string): ParsedIni => { let currentSection: string | undefined; filteredLines.forEach((line) => { - const isParameter: boolean = regexPatterns.param.test(line); - const isSection: boolean = regexPatterns.section.test(line); - if (isParameter && currentSection) { - const match: RegExpMatchArray | null = line.match(regexPatterns.param); - - if (match) { - const matchKey: string = match[1].toLowerCase(); - const matchValue: string = match[2]; - parsedIni[currentSection][matchKey] = valueHandler(matchKey, matchValue); - } - } else if (isSection) { - const match: RegExpMatchArray | null = line.match(regexPatterns.section); - - if (match) { - const matchKey: string = match[1].toLowerCase(); - parsedIni[matchKey] = {}; - currentSection = matchKey; - } + const paramMatch: RegExpMatchArray | null = line.match(regexPatterns.param); + const sectionMatch: RegExpMatchArray | null = line.match(regexPatterns.section); + if (paramMatch && currentSection) { + const matchKey: string = paramMatch[1].toLowerCase(); + const matchValue: string = paramMatch[2]; + parsedIni[currentSection][matchKey] = matchValue; + } else if (sectionMatch) { + const matchKey: string = sectionMatch[1].toLowerCase(); + parsedIni[matchKey] = {}; + currentSection = matchKey; } }); |
