File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ function contentTypeForNew (req) {
29
29
return contentTypeForNew
30
30
}
31
31
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
+
32
39
// Handles a PATCH request
33
40
async function patchHandler ( req , res , next ) {
34
41
debug ( `PATCH -- ${ req . originalUrl } ` )
@@ -102,7 +109,7 @@ function readGraph (resource) {
102
109
// If the file does not exist, assume empty contents
103
110
// (it will be created after a successful patch)
104
111
if ( err . code === 'ENOENT' ) {
105
- fileContents = resource . contentType . includes ( 'json' ) ? JSON . stringify ( '{}' ) : ''
112
+ fileContents = contentForNew ( resource . contentType )
106
113
// Fail on all other errors
107
114
} else {
108
115
return reject ( error ( 500 , `Original file read error: ${ err } ` ) )
Original file line number Diff line number Diff line change @@ -95,6 +95,33 @@ describe('PATCH', () => {
95
95
result : '[{"@id":"https://tim.localhost:7777/x","https://tim.localhost:7777/y":[{"@id":"https://tim.localhost:7777/z"}]}]'
96
96
} ) )
97
97
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
+
98
125
describe ( 'on a resource with read-only access' , describePatch ( {
99
126
path : '/read-only.ttl' ,
100
127
patch : `<> a solid:InsertDeletePatch;
You can’t perform that action at this time.
0 commit comments