Skip to content

Commit

Permalink
Use underscore instead of dash in bnode names
Browse files Browse the repository at this point in the history
This is safer for use in SPARQL queries.
  • Loading branch information
rubensworks committed Sep 16, 2020
1 parent e915423 commit c0ffe27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/DataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DataFactory<Q extends RDF.BaseQuad = RDF.Quad> implements RDF.DataF
* @see BlankNode
*/
public blankNode(value?: string): BlankNode {
return new BlankNode(value || `df-${this.blankNodeCounter++}`);
return new BlankNode(value || `df_${this.blankNodeCounter++}`);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions test/DataFactory-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ describe('DataFactory', () => {
});

it('should generate a blank node label without a given label', () => {
expect(factory.blankNode().value).toEqual('df-0');
expect(factory.blankNode().value).toEqual('df-1');
expect(factory.blankNode().value).toEqual('df-2');
expect(factory.blankNode().value).toEqual('df_0');
expect(factory.blankNode().value).toEqual('df_1');
expect(factory.blankNode().value).toEqual('df_2');
});

it('should generate a blank node label without a given label and consider resets on the factory', () => {
expect(factory.blankNode().value).toEqual('df-0');
expect(factory.blankNode().value).toEqual('df-1');
expect(factory.blankNode().value).toEqual('df_0');
expect(factory.blankNode().value).toEqual('df_1');
factory.resetBlankNodeCounter();
expect(factory.blankNode().value).toEqual('df-0');
expect(factory.blankNode().value).toEqual('df-1');
expect(factory.blankNode().value).toEqual('df_0');
expect(factory.blankNode().value).toEqual('df_1');
});

it('should handle equals', () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('DataFactory', () => {
.equals(factory.literal('a', factory.namedNode('ex:dt')))).toEqual(false);
expect(factory.literal('a', 'en-us')
.equals(factory.literal('a',
factory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString')))).toEqual(false);
factory.namedNode('http://www.w3.org/1999/02/22-rdf_syntax-ns#langString')))).toEqual(false);

expect(factory.literal('a', factory.namedNode('ex:dt'))
.equals(factory.literal('a'))).toEqual(false);
Expand Down

0 comments on commit c0ffe27

Please sign in to comment.