Skip to content
Permalink
Browse files

Fix crash when bindings without children are present

  • Loading branch information...
rubensworks committed Sep 21, 2018
1 parent 3e28537 commit ed2e9ee1a75ed8a1a548020c02c35a36f9b4f76b
Showing with 43 additions and 2 deletions.
  1. +1 −1 lib/SparqlXmlParser.ts
  2. +42 −1 test/SparqlXmlParser-test.ts
@@ -60,7 +60,7 @@ export class SparqlXmlParser {
const bindingsArray = Array.isArray(rawBindings.children.binding)
? rawBindings.children.binding : [rawBindings.children.binding];
for (const binding of bindingsArray) {
if (binding.attribs) {
if (binding.attribs && binding.children) {
const key = binding.attribs.name;
let value: RDF.Term = null;
if (binding.children.bnode) {
@@ -287,7 +287,8 @@ describe('SparqlXmlParser', () => {
<?xml version="1.0"?>abc`)))).rejects.toBeTruthy();
});

it('should emit an error on an invalid SPARQL XML response\'', async () => {
it('should emit an error when an unexpected error occurs in parseXmlBindings', async () => {
parser.parseXmlBindings = null;
return expect(arrayifyStream(parser.parseXmlResultsStream(streamifyString(`<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
@@ -308,6 +309,46 @@ describe('SparqlXmlParser', () => {
});

describe('#parseXmlBindings', () => {
it('should convert bindings with no attributes', () => {
const binding = {
children: {
binding: [
{
children: {
uri: { value: 'http://example.org/book/book6' },
},
},
],
},
};
return expect(parser.parseXmlBindings(binding)).toEqual({});
});

it('should convert bindings with no children', () => {
const binding = {
children: {
binding: [
{
attribs: { name: 'book' },
},
],
},
};
return expect(parser.parseXmlBindings(binding)).toEqual({});
});

it('should convert bindings with no attributes and children', () => {
const binding = {
children: {
binding: [
{
},
],
},
};
return expect(parser.parseXmlBindings(binding)).toEqual({});
});

it('should convert bindings with named nodes', () => {
const binding = {
children: {

0 comments on commit ed2e9ee

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