Skip to content

Commit c791802

Browse files
committed
update default content for rdf+xml
1 parent 4a596df commit c791802

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/handlers/patch.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ function contentTypeForNew (req) {
2929
return contentTypeForNew
3030
}
3131

32+
function contentForNew (contentType) {
33+
let contentForNew = ''
34+
if (contentType.includes('ld+json')) contentForNew = JSON.stringify('{}')
35+
else if (contentType.includes('rdf+xml')) contentForNew = '<rdf:RDF\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n\n</rdf:RDF>'
36+
return contentForNew
37+
}
38+
3239
// Handles a PATCH request
3340
async function patchHandler (req, res, next) {
3441
debug(`PATCH -- ${req.originalUrl}`)
@@ -102,7 +109,7 @@ function readGraph (resource) {
102109
// If the file does not exist, assume empty contents
103110
// (it will be created after a successful patch)
104111
if (err.code === 'ENOENT') {
105-
fileContents = resource.contentType.includes('json') ? JSON.stringify('{}') : ''
112+
fileContents = contentForNew(resource.contentType)
106113
// Fail on all other errors
107114
} else {
108115
return reject(error(500, `Original file read error: ${err}`))

test/integration/patch-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ describe('PATCH', () => {
9595
result: '[{"@id":"https://tim.localhost:7777/x","https://tim.localhost:7777/y":[{"@id":"https://tim.localhost:7777/z"}]}]'
9696
}))
9797

98+
describe('on a non-existent RDF+XML file', describePatch({
99+
path: '/new.rdf',
100+
exists: false,
101+
patch: `<> a solid:InsertDeletePatch;
102+
solid:inserts { <x> <y> <z>. }.`
103+
}, { // expected:
104+
status: 200,
105+
text: 'Patch applied successfully',
106+
result: `<rdf:RDF
107+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
108+
xmlns:tim="https://tim.localhost:7777/">
109+
<rdf:Description rdf:about="/x"><tim:y rdf:resource="/z"/></rdf:Description>
110+
</rdf:RDF>
111+
`
112+
}))
113+
114+
describe('on a non-existent N3 file', describePatch({
115+
path: '/new.n3',
116+
exists: false,
117+
patch: `<> a solid:InsertDeletePatch;
118+
solid:inserts { <x> <y> <z>. }.`
119+
}, { // expected:
120+
status: 200,
121+
text: 'Patch applied successfully',
122+
result: '@prefix : </new.n3#>.\n@prefix tim: </>.\n\ntim:x tim:y tim:z.\n\n'
123+
}))
124+
98125
describe('on a resource with read-only access', describePatch({
99126
path: '/read-only.ttl',
100127
patch: `<> a solid:InsertDeletePatch;

0 commit comments

Comments
 (0)