aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOsmium Sorcerer <os@sof.beauty>2026-03-16 15:32:37 +0000
committerOsmium Sorcerer <os@sof.beauty>2026-04-18 16:52:22 +0000
commitc291a9b769d48aab72f5c133dd71e554a09b5d1a (patch)
tree80d03003a2141c27f00d623ef0f37add3b4e795b
parent8538104fd5573ba5eeade30ee4a20893224960f9 (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.ts32
1 files changed, 10 insertions, 22 deletions
diff --git a/webAO/iniParse.ts b/webAO/iniParse.ts
index ca84c35..74bd764 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;
}
});