Skip to content
Permalink
Browse files

Catch SPARQL XML errors

  • Loading branch information...
rubensworks committed Aug 24, 2018
1 parent 271911f commit 74787ade801564b2aaf09c50720478aa6c6b3dc3
Showing with 27 additions and 2 deletions.
  1. +7 −1 lib/SparqlXmlBindingsTransformer.ts
  2. +20 −1 test/SparqlXmlParser-test.ts
@@ -14,7 +14,13 @@ export class SparqlXmlBindingsTransformer extends Transform {
}

public _transform(chunk: any, encoding: string, callback: TransformCallback): void {
callback(null, this.parser.parseXmlBindings(chunk));
let bindings;
try {
bindings = this.parser.parseXmlBindings(chunk);
} catch (e) {
return callback(e);
}
callback(null, bindings);
}

}
@@ -232,10 +232,29 @@ describe('SparqlXmlParser', () => {
return expect(arrayifyStream(parser.parseXmlResultsStream(errorStream))).rejects.toBeTruthy();
});

it('should emit an error on an invalid SPARQL XML response\'', async () => {
it('should emit an error on an invalid XML response\'', async () => {
return expect(arrayifyStream(parser.parseXmlResultsStream(streamifyString(`
<?xml version="1.0"?>abc`)))).rejects.toBeTruthy();
});

it('should emit an error on an invalid SPARQL XML response\'', async () => {
return expect(arrayifyStream(parser.parseXmlResultsStream(streamifyString(`<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="x"/>
<variable name="hpage"/>
<variable name="name"/>
<variable name="age"/>
<variable name="mbox"/>
<variable name="friend"/>
</head>
<results>
<result>
<binding name="x" />
</result>
</results>
</sparql>`)))).rejects.toBeTruthy();
});
});

describe('#parseXmlBindings', () => {

0 comments on commit 74787ad

Please sign in to comment.
You can’t perform that action at this time.