Skip to content

Commit 89f2e9a

Browse files
authored
Abbreviate local names starting with underscores.
1 parent e531951 commit 89f2e9a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/N3Writer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export default class N3Writer {
296296
}
297297
IRIlist = escapeRegex(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
298298
this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` +
299-
`^(${IRIlist})([a-zA-Z][\\-_a-zA-Z0-9]*)$`);
299+
`^(${IRIlist})([_a-zA-Z][\\-_a-zA-Z0-9]*)$`);
300300
}
301301
// End a prefix block with a newline
302302
this._write(hasPrefixes ? '\n' : '', done);

test/N3Writer-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ describe('Writer', () => {
307307
});
308308
});
309309

310+
it('should serialize triples of graph with prefix for local names that begin with underscore', done => {
311+
const writer = new Writer();
312+
writer.addPrefix('a', 'b#');
313+
writer.addQuad(new Quad(new NamedNode('b#_a'), new NamedNode('b#b'), new NamedNode('b#c'), new NamedNode('b#g')));
314+
writer.end((error, output) => {
315+
output.should.equal('@prefix a: <b#>.\n\na:g {\na:_a a:b a:c\n}\n');
316+
done(error);
317+
});
318+
});
319+
310320
it('serializes triples of a graph with a prefix declaration in between', done => {
311321
const writer = new Writer();
312322
writer.addQuad(new Quad(new NamedNode('b#a'), new NamedNode('b#b'), new NamedNode('b#c')));

0 commit comments

Comments
 (0)