Skip to content

Commit

Permalink
Changes for broken struct issue with text parser (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
desaikd committed Mar 16, 2021
1 parent 9d23316 commit 82b940c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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;
}
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();

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

0 comments on commit 82b940c

Please sign in to comment.