Skip to content

Commit

Permalink
fix: repeated nested keys (#2)
Browse files Browse the repository at this point in the history
Repeating nested keys when `arrayRepeat` is `true` should result in an
array of the multiple values. This fixes the functionality.
  • Loading branch information
43081j authored Jun 20, 2024
1 parent ac79f17 commit 904c983
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function parse(input: string, options?: UserParseOptions): ParsedQuery {
(currentValue as unknown[]).push(newValue);
} else {
if (shouldDoNesting) {
dset(result, newKey as string, [currentValue, newValue]);
dset(result, dlvKey, [currentValue, newValue]);
} else {
result[newKey] = [currentValue, newValue];
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ const testCases: TestCase[] = [
output: {foo: ['x', 'y']},
options: {arrayRepeat: true, arrayRepeatSyntax: 'repeat'}
},
{
input: 'foo.bar=x&foo.bar=y',
output: {foo: {bar: ['x', 'y']}},
options: {arrayRepeat: true, arrayRepeatSyntax: 'repeat'}
},

// Nesting syntax: index
{
Expand Down

0 comments on commit 904c983

Please sign in to comment.