From 7f75eeb133344f3949c43cd5d99f33a8755a2e08 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Thu, 10 Aug 2023 16:29:17 +0200 Subject: [PATCH] Do not repeat identical blank nodes as subject. Fixes https://github.com/rdfjs/N3.js/issues/360 --- src/N3Writer.js | 4 ++-- test/N3Writer-test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/N3Writer.js b/src/N3Writer.js index abc3852f..cdce5e49 100644 --- a/src/N3Writer.js +++ b/src/N3Writer.js @@ -19,8 +19,8 @@ const escape = /["\\\t\n\r\b\f\u0000-\u0019\ud800-\udbff]/, class SerializedTerm extends Term { // Pretty-printed nodes are not equal to any other node // (e.g., [] does not equal []) - equals() { - return false; + equals(other) { + return other === this; } } diff --git a/test/N3Writer-test.js b/test/N3Writer-test.js index 33660145..e77ab213 100644 --- a/test/N3Writer-test.js +++ b/test/N3Writer-test.js @@ -402,6 +402,18 @@ describe('Writer', () => { }); }); + it('should serialize triples with the same blank node as object', done => { + const writer = new Writer(); + const blank = writer.blank(); + writer.addQuad(blank, new NamedNode('a'), new NamedNode('b')); + writer.addQuad(blank, new NamedNode('c'), new NamedNode('d')); + writer.end((error, output) => { + output.should.equal('[] ;\n' + + ' .\n'); + done(error); + }); + }); + it('should serialize triples with a one-triple blank node as object', done => { const writer = new Writer(); writer.addQuad(new NamedNode('a1'), new NamedNode('b'), writer.blank(new NamedNode('d'), new NamedNode('e')));