Skip to content

Commit

Permalink
fix(parser): breaks if there are special characters in attribute list
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Mar 25, 2024
1 parent 0c9cf36 commit ffe9021
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 46 deletions.
5 changes: 4 additions & 1 deletion src/xschem-parser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ Pair
= key:PropertyName _ "=" _ value:PropertyValue {
return [key, value];
}
/ key:PropertyName {
return [];
}

PropertyName
= [a-zA-Z0-9_]+ { return text(); }
= [^ \r\n\t;"\\=}]+ { return text(); }

PropertyValue
= str:QuotedString { return str.replace(/\\./g, m => m[1]);}
Expand Down
32 changes: 32 additions & 0 deletions src/xschem-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,36 @@ spiceprefix=X
},
]);
});

it('parses an attribute that has non standard characters in its key', () => {
const content = `B 2 1400 -440 1660 -260 {+|=bar}`;
const result = parse(content);
expect(result).toEqual([
{
type: 'Rectangle',
x1: 1400,
y1: -440,
x2: 1660,
y2: -260,
layer: 2,
properties: { '+|': 'bar' },
},
]);
});

it('parses an attribute list with garbage', () => {
const content = `B 2 1400 -440 1660 -260 {foo bar baz | + name=test}`;
const result = parse(content);
expect(result).toEqual([
{
type: 'Rectangle',
x1: 1400,
y1: -440,
x2: 1660,
y2: -260,
layer: 2,
properties: { name: 'test' },
},
]);
});
});
Loading

0 comments on commit ffe9021

Please sign in to comment.