Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var $rdf = require('rdflib')
var S = require('string')
var async = require('async')
var Negotiator = require('negotiator')
const url = require('url')

var debug = require('debug')('solid:get')
var debugGlob = require('debug')('solid:glob')
Expand Down Expand Up @@ -132,6 +133,7 @@ function globHandler (req, res, next) {
var root = !ldp.idp ? ldp.root : ldp.root + req.hostname + '/'
var filename = utils.uriToFilename(req.path, root)
var uri = utils.uriBase(req)
const requestUri = url.resolve(uri, req.path)

var globOptions = {
noext: true,
Expand Down Expand Up @@ -176,7 +178,7 @@ function globHandler (req, res, next) {
var data = $rdf.serialize(
undefined,
globGraph,
null,
requestUri,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is still untested.

'text/turtle')
// TODO this should be added as a middleware in the routes
res.setHeader('Content-Type', 'text/turtle')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"node-forge": "^0.6.38",
"nodemailer": "^3.1.4",
"nomnom": "^1.8.1",
"rdflib": "^0.12.3",
"rdflib": "^0.15.0",
"recursive-readdir": "^2.1.0",
"request": "^2.72.0",
"rimraf": "^2.5.0",
Expand Down
26 changes: 25 additions & 1 deletion test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var li = require('li')
var ldnode = require('../index')
var rm = require('./test-utils').rm
var path = require('path')
const rdf = require('rdflib')

var suffixAcl = '.acl'
var suffixMeta = '.meta'
Expand Down Expand Up @@ -288,7 +289,30 @@ describe('HTTP APIs', function () {
it('should have glob support', function (done) {
server.get('/sampleContainer/example*')
.expect('content-type', /text\/turtle/)
.expect(200, done)
.expect(200)
.expect((res) => {
let kb = rdf.graph()
rdf.parse(res.text, kb, 'https://localhost/', 'text/turtle')

assert(kb.match(
rdf.namedNode('https://localhost/example1.ttl#this'),
rdf.namedNode('http://purl.org/dc/elements/1.1/title'),
rdf.literal('Test title')
).length, 'Must contain a triple from example1.ttl')

assert(kb.match(
rdf.namedNode('http://example.org/stuff/1.0/a'),
rdf.namedNode('http://example.org/stuff/1.0/b'),
rdf.literal('apple')
).length, 'Must contain a triple from example2.ttl')

assert(kb.match(
rdf.namedNode('http://example.org/stuff/1.0/a'),
rdf.namedNode('http://example.org/stuff/1.0/b'),
rdf.literal('The first line\nThe second line\n more')
).length, 'Must contain a triple from example3.ttl')
})
.end(done)
})
it('should have set acl and describedBy Links for container',
function (done) {
Expand Down
50 changes: 37 additions & 13 deletions test/patch-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,31 @@ describe('PATCH', function () {

describe('DELETE', function () {
it('reproduce index 1 bug from pad', function (done) {
var expected = '@prefix dc: <http://purl.org/dc/elements/1.1/>.\n@prefix meeting: <http://www.w3.org/ns/pim/meeting#>.\n@prefix card: <https://www.w3.org/People/Berners-Lee/card#>.\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.\n@prefix p: <http://www.w3.org/ns/pim/pad#>.\n@prefix in: </parent/index.ttl#>.\n@prefix n: <http://rdfs.org/sioc/ns#>.\n@prefix flow: <http://www.w3.org/2005/01/wf/flow#>.\n@prefix ic: <http://www.w3.org/2002/12/cal/ical#>.\n@prefix ui: <http://www.w3.org/ns/ui#>.\n\n<#this>\n dc:author\n card:i;\n dc:created\n "2016-10-25T15:44:42Z"^^xsd:dateTime;\n dc:title\n "Shared Notes";\n a p:Notepad;\n p:next\n <#id1477502276660>.\n in:this flow:participation <#id1477522707481>; meeting:sharedNotes <#this> .\n <#id1477502276660> dc:author card:i; n:content ""; p:next <#this> .\n<#id1477522707481>\n ic:dtstart\n "2016-10-26T22:58:27Z"^^xsd:dateTime;\n flow:participant\n card:i;\n ui:backgroundColor\n "#c1d0c8".\n'
var expected = `@prefix : </existingTriple.ttl#>.
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix c: <https://www.w3.org/People/Berners-Lee/card#>.
@prefix n: <http://rdfs.org/sioc/ns#>.
@prefix p: <http://www.w3.org/ns/pim/pad#>.
@prefix ic: <http://www.w3.org/2002/12/cal/ical#>.
@prefix XML: <http://www.w3.org/2001/XMLSchema#>.
@prefix flow: <http://www.w3.org/2005/01/wf/flow#>.
@prefix ui: <http://www.w3.org/ns/ui#>.
@prefix ind: </parent/index.ttl#>.
@prefix mee: <http://www.w3.org/ns/pim/meeting#>.

:id1477502276660 dc:author c:i; n:content ""; p:next :this.

:id1477522707481
ic:dtstart "2016-10-26T22:58:27Z"^^XML:dateTime;
flow:participant c:i;
ui:backgroundColor "#c1d0c8".
:this
a p:Notepad;
dc:author c:i;
dc:created "2016-10-25T15:44:42Z"^^XML:dateTime;
dc:title "Shared Notes";
p:next :id1477502276660.
ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`

write(`\n\

Expand Down Expand Up @@ -109,10 +133,10 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/prefixSparql.ttl'),
'@prefix : </prefixSparql.ttl#>.\n' +
'@prefix schema: <http://schema.org/>.\n' +
'@prefix profile: <http://ogp.me/ns/profile#>.\n' +
'\n' +
' <#> profile:first_name "Timothy"; a schema:Person .\n')
'@prefix pro: <http://ogp.me/ns/profile#>.\n\n' +
': a schema:Person; pro:first_name "Timothy".\n\n')
rm('sampleContainer/prefixSparql.ttl')
done(err)
})
Expand All @@ -131,9 +155,9 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTriple.ttl'),
'\n' +
' <#current> <#temp> 123 .\n' +
' <#test> <#hello> 456 .\n')
'@prefix : </addingTriple.ttl#>.\n\n' +
':current :temp 123 .\n\n' +
':test :hello 456 .\n\n')
rm('sampleContainer/addingTriple.ttl')
done(err)
})
Expand All @@ -150,8 +174,8 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTripleValue.ttl'),
'\n' +
' <#current> <#temp> 123, 456 .\n')
'@prefix : </addingTripleValue.ttl#>.\n\n' +
':current :temp 123, 456 .\n\n')
rm('sampleContainer/addingTripleValue.ttl')
done(err)
})
Expand All @@ -168,8 +192,8 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTripleSubj.ttl'),
'\n' +
' <#current> <#temp2> 456; <#temp> 123 .\n')
'@prefix : </addingTripleSubj.ttl#>.\n\n' +
':current :temp 123; :temp2 456 .\n\n')
rm('sampleContainer/addingTripleSubj.ttl')
done(err)
})
Expand All @@ -187,8 +211,8 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/emptyExample.ttl'),
'\n' +
' <#current> <#temp> 123 .\n')
'@prefix : </emptyExample.ttl#>.\n\n' +
':current :temp 123 .\n\n')
rm('sampleContainer/emptyExample.ttl')
done(err)
})
Expand Down
30 changes: 16 additions & 14 deletions test/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ describe('PATCH', function () {

it('should create a new file if file does not exist', function (done) {
rm('sampleContainer/notExisting.ttl')

server.patch('/notExisting.ttl')
.set('content-type', 'application/sparql-update')
.send('INSERT DATA { :test :hello 456 .}')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/notExisting.ttl'),
'\n <#test> <#hello> 456 .\n')
'@prefix : </notExisting.ttl#>.\n\n' +
':test :hello 456 .\n\n')
rm('sampleContainer/notExisting.ttl')
done(err)
})
Expand All @@ -44,7 +46,7 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/existingTriple.ttl'),
'\n')
'@prefix : </existingTriple.ttl#>.\n\n')
rm('sampleContainer/existingTriple.ttl')
done(err)
})
Expand Down Expand Up @@ -72,10 +74,10 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/prefixSparql.ttl'),
'@prefix : </prefixSparql.ttl#>.\n' +
'@prefix schema: <http://schema.org/>.\n' +
'@prefix profile: <http://ogp.me/ns/profile#>.\n' +
'\n' +
' <#> profile:first_name "Timothy"; a schema:Person .\n')
'@prefix pro: <http://ogp.me/ns/profile#>.\n\n' +
': a schema:Person; pro:first_name "Timothy".\n\n')
rm('sampleContainer/prefixSparql.ttl')
done(err)
})
Expand All @@ -94,9 +96,9 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTriple.ttl'),
'\n' +
' <#current> <#temp> 123 .\n' +
' <#test> <#hello> 456 .\n')
'@prefix : </addingTriple.ttl#>.\n\n' +
':current :temp 123 .\n\n' +
':test :hello 456 .\n\n')
rm('sampleContainer/addingTriple.ttl')
done(err)
})
Expand All @@ -113,8 +115,8 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTripleValue.ttl'),
'\n' +
' <#current> <#temp> 123, 456 .\n')
'@prefix : </addingTripleValue.ttl#>.\n\n' +
':current :temp 123, 456 .\n\n')
rm('sampleContainer/addingTripleValue.ttl')
done(err)
})
Expand All @@ -131,8 +133,8 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTripleSubj.ttl'),
'\n' +
' <#current> <#temp2> 456; <#temp> 123 .\n')
'@prefix : </addingTripleSubj.ttl#>.\n\n' +
':current :temp 123; :temp2 456 .\n\n')
rm('sampleContainer/addingTripleSubj.ttl')
done(err)
})
Expand All @@ -150,8 +152,8 @@ describe('PATCH', function () {
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/emptyExample.ttl'),
'\n' +
' <#current> <#temp> 123 .\n')
'@prefix : </emptyExample.ttl#>.\n\n' +
':current :temp 123 .\n\n')
rm('sampleContainer/emptyExample.ttl')
done(err)
})
Expand Down
2 changes: 2 additions & 0 deletions test/resources/sampleContainer/example1.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ex: <http://example.org/stuff/1.0/> .

<#this> dc:title "Test title" .

<http://www.w3.org/TR/rdf-syntax-grammar>
dc:title "RDF/XML Syntax Specification (Revised)" ;
ex:editor [
Expand Down
6 changes: 1 addition & 5 deletions test/resources/sampleContainer/example2.ttl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
@prefix : <http://example.org/stuff/1.0/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
:a :b
[ rdf:first "apple";
rdf:rest [ rdf:first "banana";
rdf:rest rdf:nil ]
] .
:a :b "apple" .