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

Changes for broken struct issue with text parser #684

Merged
merged 5 commits into from
Mar 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/IonParserTextRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ export class ParserTextRaw {
ch = this._read_after_whitespace(true);
if (ch != CH_CL) {
this._error("expected ':'");
return;
desaikd marked this conversation as resolved.
Show resolved Hide resolved
}
this._ops.unshift(this._read_struct_comma);
this._ops.unshift(this._read_value);
Expand Down
13 changes: 13 additions & 0 deletions test/IonTextReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ class IonTextReaderTests {
assert.isNull(ionReader.next());
}

@test "Parse through struct throws error on broken input"() {
let invalidIonToRead = "{broken";

let ionReader = ion.makeReader(invalidIonToRead);
ionReader.next();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't you use const instead of let since you don't modify or change the value of invalidIonToRead and ionReader

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrading let to const where appropriate is something we intend to do project-wide via one of our linting tools but haven't had the opportunity yet. Once we do, new code will be required to const where possible.

assert.equal(ion.IonTypes.STRUCT, ionReader.type());

ionReader.stepIn(); // Step into the base struct.

assert.throws(() => ionReader.next());
}

@test "Reads an array"() {
let ionToRead = "{ key : ['v1', 'v2'] }";
let ionReader = ion.makeReader(ionToRead);
Expand Down
2 changes: 1 addition & 1 deletion test/dom/Value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe("Value", () => {
assert.equal(ionSExpression.length, LARGE_CONTAINER_NUM_ENTRIES);
});
it("Struct", function () {
this.timeout(5_000);
this.timeout(6_000);
let ionStruct = Value.from(largeJsObject) as any;
assert.equal(ionStruct.getType(), IonTypes.STRUCT);
assert.equal(ionStruct.fields().length, LARGE_CONTAINER_NUM_ENTRIES);
Expand Down
3 changes: 3 additions & 0 deletions test/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ describe('DOM', () => {
}

assert.equal(2, s.fields().length)

// broken struct
assert.throws(() => load('{broken'));
});

it('load() Struct with duplicate fields as any', () => {
Expand Down