Skip to content

Commit f9a392c

Browse files
committed
Fix parsing of empty relative IRIs.
1 parent dd7a21a commit f9a392c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/N3Parser.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ N3Parser.prototype = {
222222
return this._readQuantifierList;
223223
default:
224224
// Read the subject entity
225-
if (!(this._subject = this._readEntity(token)))
225+
if ((this._subject = this._readEntity(token)) === undefined)
226226
return;
227227
// In N3 mode, the subject might be a path
228228
if (this._n3Mode)
@@ -258,7 +258,7 @@ N3Parser.prototype = {
258258
if (!this._n3Mode)
259259
return this._error('Disallowed blank node as predicate', token);
260260
default:
261-
if (!(this._predicate = this._readEntity(token)))
261+
if ((this._predicate = this._readEntity(token)) === undefined)
262262
return;
263263
}
264264
// The next token must be an object.
@@ -290,7 +290,7 @@ N3Parser.prototype = {
290290
return this._readSubject;
291291
default:
292292
// Read the object entity
293-
if (!(this._object = this._readEntity(token)))
293+
if ((this._object = this._readEntity(token)) === undefined)
294294
return;
295295
// In N3 mode, the object might be a path
296296
if (this._n3Mode)
@@ -433,7 +433,7 @@ N3Parser.prototype = {
433433
next = this._readDataTypeOrLang;
434434
break;
435435
default:
436-
if (!(item = this._readEntity(token)))
436+
if ((item = this._readEntity(token)) === undefined)
437437
return;
438438
}
439439

@@ -513,7 +513,7 @@ N3Parser.prototype = {
513513
break;
514514
default:
515515
// An entity means this is a quad (only allowed if not already inside a graph).
516-
if (this._supportsQuads && this._graph === null && (graph = this._readEntity(token))) {
516+
if (this._supportsQuads && this._graph === null && (graph = this._readEntity(token)) !== undefined) {
517517
next = this._readQuadPunctuation;
518518
break;
519519
}
@@ -625,7 +625,7 @@ N3Parser.prototype = {
625625
switch (token.type) {
626626
case 'IRI':
627627
case 'prefixed':
628-
if (entity = this._readEntity(token, true))
628+
if ((entity = this._readEntity(token, true)) !== undefined)
629629
break;
630630
default:
631631
return this._error('Unexpected ' + token.type, token);
@@ -700,7 +700,7 @@ N3Parser.prototype = {
700700
_readForwardPath: function (token) {
701701
var subject, predicate, object = '_:b' + blankNodeCount++;
702702
// The next token is the predicate
703-
if (!(predicate = this._readEntity(token)))
703+
if ((predicate = this._readEntity(token)) === undefined)
704704
return;
705705
// If we were reading a subject, replace the subject by the path's object
706706
if (this._predicate === null)
@@ -717,7 +717,7 @@ N3Parser.prototype = {
717717
_readBackwardPath: function (token) {
718718
var subject = '_:b' + blankNodeCount++, predicate, object;
719719
// The next token is the predicate
720-
if (!(predicate = this._readEntity(token)))
720+
if ((predicate = this._readEntity(token)) === undefined)
721721
return;
722722
// If we were reading a subject, replace the subject by the path's subject
723723
if (this._predicate === null)

test/N3Parser-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ describe('N3Parser', function () {
176176
['a', 'b', 'c'],
177177
['a', 'b', 'd']));
178178

179+
it('should parse diamonds',
180+
shouldParse('<> <> <> <>.\n(<>) <> (<>) <>.',
181+
['', '', '', ''],
182+
['_:b0', '', '_:b1', ''],
183+
['_:b0', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', ''],
184+
['_:b0', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'],
185+
['_:b1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', ''],
186+
['_:b1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil']));
187+
179188
it('should parse statements with named blank nodes',
180189
shouldParse('_:a <b> _:c.',
181190
['_:b0_a', 'b', '_:b0_c']));

0 commit comments

Comments
 (0)