Skip to content

Commit

Permalink
fix parsing of empty arrays and dicts in openstep plists
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed Jan 10, 2024
1 parent 0a35ec6 commit 01f280c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/openstep.parse/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ describe('openstep:parse', () => {
});

describe('array', () => {
it('parses empty arrays', () => {
expect(parse('()')).toStrictEqual([]);
expect(
parse(`
{
classes = (
);
}`)
).toStrictEqual({ classes: [] });
});

it('parses string arrays', () => {
expect(parse('("a", "b", "c")')).toStrictEqual(['a', 'b', 'c']);
expect(parse('(a, b, c)')).toStrictEqual(['a', 'b', 'c']);
Expand All @@ -62,6 +73,13 @@ describe('openstep:parse', () => {
describe('dict', () => {
it('parses empty dicts', () => {
expect(parse('{}')).toStrictEqual({});
expect(
parse(`
{
classes = {
};
}`)
).toStrictEqual({ classes: {} });
});

it('parses dicts', () => {
Expand Down
19 changes: 18 additions & 1 deletion packages/openstep.parse/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ const consumeValue = (input: string): [Value, string] => {
case '{':
result = {};

[, input] = consumeWhitespaceAndComments(input);
if (input.charAt(0) === '}') {
[, input] = consumeToken(input, '}');
break;
}

while (input.charAt(0) !== '}') {
let key: Value, value: Value;
[key, input] = consumeValue(input);
Expand All @@ -113,6 +119,12 @@ const consumeValue = (input: string): [Value, string] => {
case '(':
result = [];

[, input] = consumeWhitespaceAndComments(input);
if (input.charAt(0) === ')') {
[, input] = consumeToken(input, ')');
break;
}

while (input.charAt(0) !== ')') {
let value: Value, token: string | null;
[value, input] = consumeValue(input);
Expand All @@ -131,9 +143,14 @@ const consumeValue = (input: string): [Value, string] => {
[, input] = consumeToken(input, ')');
break;
case '<':
let array = new Uint8Array();
let hexString = '';

[, input] = consumeWhitespaceAndComments(input);
if (input.charAt(0) === '>') {
[, input] = consumeToken(input, '>');
break;
}

while (input.charAt(0) !== '>') {
const digit = input.charAt(0);
input = input.substr(1);
Expand Down

0 comments on commit 01f280c

Please sign in to comment.