Comparing version 0.3.1 to 0.3.2
@@ -9,5 +9,5 @@ // **N3Parser** parses N3 documents. | ||
var absoluteURI = /^[a-z]+:/, | ||
var absoluteURI = /:/, | ||
documentPart = /[^\/]*$/, | ||
rootURI = /^(?:[a-z]+:\/*)?[^\/]*/; | ||
rootURI = /^(?:[^:]+:\/*)?[^\/]*/; | ||
@@ -14,0 +14,0 @@ var _undefined, noop = function () {}; |
@@ -27,3 +27,3 @@ // **N3Util** provides N3 utility functions | ||
getLiteralValue: function (literal) { | ||
var match = /^"((?:.|\n|\r)*)"/.exec(literal); | ||
var match = /^"([^]*)"/.exec(literal); | ||
if (!match) | ||
@@ -36,3 +36,3 @@ throw new Error(literal + ' is not a literal'); | ||
getLiteralType: function (literal) { | ||
var match = /^"(?:.|\n|\r)*"(?:\^\^(.+)|(@)[\-a-z]+)?$/i.exec(literal); | ||
var match = /^"[^]*"(?:\^\^(.+)|(@)[\-a-z]+)?$/i.exec(literal); | ||
if (!match) | ||
@@ -45,3 +45,3 @@ throw new Error(literal + ' is not a literal'); | ||
getLiteralLanguage: function (literal) { | ||
var match = /^"(?:.|\n|\r)*"(?:@([\-a-z]+)|\^\^.+)?$/i.exec(literal); | ||
var match = /^"[^]*"(?:@([\-a-z]+)|\^\^.+)?$/i.exec(literal); | ||
if (!match) | ||
@@ -48,0 +48,0 @@ throw new Error(literal + ' is not a literal'); |
@@ -109,2 +109,7 @@ // **N3Writer** writes N3 documents. | ||
// ### `_blockedWrite` replaces `_writer_ after the writer has been closed | ||
_blockedWrite: function () { | ||
throw new Error('Cannot write because the writer has been closed.'); | ||
}, | ||
// ### `addTriple` adds the triple to the output stream | ||
@@ -165,6 +170,8 @@ addTriple: function (subject, predicate, object, done) { | ||
addPrefix: function (prefix, uri, done) { | ||
if (/[#\/]$/.test(uri)) { | ||
var isPrefix = /[#\/]$/.test(uri); | ||
if (isPrefix) { | ||
this._prefixURIs[uri] = prefix + ':'; | ||
this._write('@prefix ', prefix, ': <', uri, '>.\n', done); | ||
} | ||
return isPrefix; | ||
}, | ||
@@ -174,5 +181,6 @@ | ||
addPrefixes: function (prefixes, done) { | ||
var hasPrefixes = false; | ||
for (var prefix in prefixes) | ||
this.addPrefix(prefix, prefixes[prefix]); | ||
this._write('\n', done); | ||
hasPrefixes = this.addPrefix(prefix, prefixes[prefix]) || hasPrefixes; | ||
this._write(hasPrefixes ? '\n' : '', done); | ||
}, | ||
@@ -187,2 +195,4 @@ | ||
} | ||
// Disallow further writing | ||
this._write = this._blockedWrite; | ||
@@ -189,0 +199,0 @@ // If writing to a string instead of an actual stream, send the string |
{ | ||
"name": "n3", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -5,0 +5,0 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", |
@@ -381,2 +381,11 @@ var N3Parser = require('../N3').Parser; | ||
it('should not resolve URIs with colons', | ||
shouldParse('@base <http://ex.org/>.\n' + | ||
'<a> <b> <c>.\n' + | ||
'<A:> <b:> <c:>.\n' + | ||
'<a:a> <b:B> <C-D:c>.', | ||
['http://ex.org/a', 'http://ex.org/b', 'http://ex.org/c'], | ||
['A:', 'b:', 'c:'], | ||
['a:a', 'b:B', 'C-D:c'])); | ||
it('should not parse base declarations without IRI', | ||
@@ -383,0 +392,0 @@ shouldNotParse('@base a: ', |
@@ -98,2 +98,7 @@ var N3Writer = require('../N3').Writer; | ||
it('should not leave leading whitespace if the prefix set is empty', | ||
shouldSerialize({}, | ||
[['a', 'b', 'c']], | ||
'<a> <b> <c>.\n')); | ||
it('should serialize valid prefixes', | ||
@@ -187,2 +192,13 @@ shouldSerialize({ a: 'http://a.org/', | ||
}); | ||
it('should not allow writing after end', function (done) { | ||
var writer = N3Writer(); | ||
writer.addTriple({ subject: 'a', predicate: 'b', object: 'c' }); | ||
writer.end(); | ||
writer.addTriple({ subject: 'd', predicate: 'e', object: 'f' }, function (error) { | ||
error.should.be.an.instanceof(Error); | ||
error.should.have.property('message', 'Cannot write because the writer has been closed.'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -189,0 +205,0 @@ }); |
191661
3867