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 xml parse error #294

Merged
merged 2 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions src/parser/SGParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ describe('SGParser', () => {
`);
});

it('does not crash when missing tag name', () => {
const parser = new SGParser();
parser.parse(
'pkg:/components/ParentScene.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="ChildScene" extends="ParentScene">
<!-- a standalone less-than symbol used to cause issues -->
<
</component>
`);
//the test passes if the parser doesn't throw a runtime exception.
});


it('Adds error when an unexpected tag is found in xml', () => {
const parser = new SGParser();
parser.parse(
Expand Down
18 changes: 11 additions & 7 deletions src/parser/SGParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,18 @@ function mapElements(content: ContentCstNode, allow: string[], diagnostics: Diag
if (element) {
for (const entry of element) {
const name = entry.children.Name?.[0];
if (name && allow.includes(name.image)) {
tags.push(mapElement(entry, diagnostics));
if (name?.image) {
if (allow.includes(name.image)) {
tags.push(mapElement(entry, diagnostics));
} else {
//unexpected tag
diagnostics.push({
...DiagnosticMessages.xmlUnexpectedTag(name.image),
range: rangeFromTokens(name)
});
}
} else {
//unexpected tag
diagnostics.push({
...DiagnosticMessages.xmlUnexpectedTag(name.image),
range: rangeFromTokens(name)
});
//bad xml syntax...
}
}
}
Expand Down