Skip to content

Commit b6e6d9e

Browse files
ryankeenerdmitrizagidulin
authored andcommitted
fixes issue where requesting a different format (e.g. text/turtle) of a jsonld resource crashed the server (nodeSolidServer#474)
1 parent e7df421 commit b6e6d9e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ function getResourceLink (filename, uri, base, suffix, otherSuffix) {
100100
function parse (data, baseUri, contentType, callback) {
101101
var graph = $rdf.graph()
102102
try {
103-
$rdf.parse(data, graph, baseUri, contentType)
103+
return $rdf.parse(data, graph, baseUri, contentType, callback)
104104
} catch (err) {
105105
return callback(err)
106106
}
107-
return callback(null, graph)
108107
}
109108

110109
function serialize (graph, baseUri, contentType, callback) {

test/formats.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ describe('formats', function () {
8383
.expect(200, done)
8484
})
8585

86+
it('should return turtle document if Accept is set to turtle', function (done) {
87+
server.get('/lennon.jsonld')
88+
.set('accept', 'text/turtle')
89+
.expect('content-type', /text\/turtle/)
90+
.expect(200, done)
91+
})
92+
8693
it('should return turtle when listing container', function (done) {
8794
server.get('/sampleContainer/')
8895
.set('accept', 'application/rdf+xml;q=0.4, application/xhtml+xml;q=0.3, text/xml;q=0.2, application/xml;q=0.2, text/html;q=0.3, text/plain;q=0.1, text/turtle;q=1.0, application/n3;q=1')

test/resources/lennon.jsonld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": "http://json-ld.org/contexts/person.jsonld",
3+
"@id": "http://dbpedia.org/resource/John_Lennon",
4+
"name": "John Lennon",
5+
"born": "1940-10-09",
6+
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
7+
}

0 commit comments

Comments
 (0)