Skip to content

Commit

Permalink
fix(ini): correctly handle quoted values in parse() (#5592)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Aug 2, 2024
1 parent 3f13395 commit 69a579e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ini/_ini_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export type ReviverFunction = (

const ASSIGNMENT_MARK = "=";

function trimQuotes(value: string): string {
if (value.startsWith('"') && value.endsWith('"')) {
return value.slice(1, -1);
}
return value;
}

/**
* Class implementation for fine control of INI data structures.
*/
Expand Down Expand Up @@ -345,7 +352,7 @@ export class IniMap {
}

const key = leftHand.trim();
const value = rightHand.trim();
const value = trimQuotes(rightHand.trim());

if (currentSection) {
const lineValue: LineValue = {
Expand Down
1 change: 1 addition & 0 deletions ini/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Deno.test({
reviver: (_, value) => Number(value),
});
assertValidParse(`a=b\n[section]\nc=d`, { a: "b", section: { c: "d" } });
assertValidParse('value="value"', { value: "value" });
assertValidParse("#comment\nkeyA=1977-05-25\n[section1]\nkeyA=100", {
keyA: "1977-05-25",
section1: { keyA: "100" },
Expand Down

0 comments on commit 69a579e

Please sign in to comment.