Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ini): correctly handle quoted values in parse() #5592

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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