Skip to content

Commit

Permalink
Do not repeat identical blank nodes as subject.
Browse files Browse the repository at this point in the history
Fixes #360
  • Loading branch information
RubenVerborgh committed Aug 10, 2023
1 parent 075e606 commit 7f75eeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/N3Writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
12 changes: 12 additions & 0 deletions test/N3Writer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[] <a> <b>;\n' +
' <c> <d>.\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')));
Expand Down

0 comments on commit 7f75eeb

Please sign in to comment.