Skip to content

Commit 7f8ff3f

Browse files
committed
Merge branch 'fix/issue#1692' of https://github.com/solid/node-solid-server into fix/issue#1692
2 parents d419882 + c68a304 commit 7f8ff3f

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

lib/ldp.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class LDP {
137137
}
138138

139139
async post (hostname, containerPath, stream, { container, slug, extension, contentType }) {
140+
console.log('container:', container)
140141
// POST without content type is forbidden
141142
if (!contentType) {
142143
throw error(400,
@@ -155,7 +156,13 @@ class LDP {
155156

156157
if (container) {
157158
// the name of a container cannot be a valid auxiliary resource document
158-
if (this._containsInvalidSuffixes(slug + '/')) slug = slug.split('.')[0]
159+
while (this._containsInvalidSuffixes(slug + '/')) {
160+
console.log('splitting slug', slug)
161+
// slug = slug.split('.')[0]
162+
const idx = slug.lastIndexOf('.')
163+
slug = slug.substr(0, idx)
164+
console.log('new slug', slug)
165+
}
159166
} else if (this.isAuxResource(slug, extension)) throw error(403, 'POST is not allowed for auxiliary resources')
160167

161168
if (slug.match(/\/|\||:/)) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"validate": "node ./test/validate-turtle.js",
147147
"nyc": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 nyc --reporter=text-summary mocha --recursive test/integration/ test/unit/",
148148
"mocha": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --recursive test/integration/ test/unit/",
149+
"mocha-integration": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --recursive test/integration/http-test.js",
149150
"prepublishOnly": "npm test",
150151
"postpublish": "git push --follow-tags",
151152
"test": "npm run standard && npm run validate && npm run nyc",

test/integration/http-test.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,6 @@ describe('HTTP APIs', function () {
891891
.set('content-type', 'text/turtle')
892892
.expect(403, done)
893893
})
894-
it('should not error with 400 if slug contains invalid suffix', function (done) { // TODO find better name
895-
server.post('/post-tests/')
896-
.set('slug', 'put-resource.acl.ttl')
897-
.send(postRequest1Body)
898-
.set('content-type', 'text-turtle')
899-
.expect(201, done)
900-
})
901894
it('should error with 400 if the body is empty and no content type is provided', function (done) {
902895
server.post('/post-tests/')
903896
.set('slug', 'post-resource-empty-fail')
@@ -921,6 +914,24 @@ describe('HTTP APIs', function () {
921914
.expect(hasHeader('acl', suffixAcl))
922915
.expect(201, done)
923916
})
917+
it('should create new resource even if slug contains invalid suffix', function (done) {
918+
server.post('/post-tests/')
919+
.set('slug', 'put-resource.acl.ttl')
920+
.send(postRequest1Body)
921+
.set('content-type', 'text-turtle')
922+
.expect(hasHeader('describedBy', suffixMeta))
923+
.expect(hasHeader('acl', suffixAcl))
924+
.expect(201, done)
925+
})
926+
it('create container with recursive example', function (done) {
927+
server.post('/post-tests/')
928+
.set('content-type', 'text/turtle')
929+
.set('slug', 'foo.bar.acl.meta')
930+
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
931+
.send(postRequest2Body)
932+
.expect('location', /\/post-tests\/foo.bar\//)
933+
.expect(201, done)
934+
})
924935
it('should fail return 404 if no parent container found', function (done) {
925936
server.post('/hello.html/')
926937
.send(postRequest1Body)

test/integration/patch-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('PATCH through text/n3', () => {
131131
result: '@prefix : </new.n3#>.\n@prefix tim: </>.\n\ntim:x tim:y tim:z.\n\n'
132132
}))
133133

134-
describe('on an N3 file that has an invalid uri', describePatch({
134+
describe('on an N3 file that has an invalid uri (*.acl)', describePatch({
135135
path: '/foo/bar.acl/test.n3',
136136
exists: false,
137137
patch: `<> a solid:InsertDeletePatch;
@@ -141,6 +141,16 @@ describe('PATCH through text/n3', () => {
141141
text: 'contained reserved suffixes in path'
142142
}))
143143

144+
describe('on an N3 file that has an invalid uri (*.meta)', describePatch({
145+
path: '/foo/bar/xyz.meta/test.n3',
146+
exists: false,
147+
patch: `<> a solid:InsertDeletePatch;
148+
solid:insers { <x> <y> <z>. }.`
149+
}, {
150+
status: 400,
151+
text: 'contained reserved suffixes in path'
152+
}))
153+
144154
describe('on a resource with read-only access', describePatch({
145155
path: '/read-only.ttl',
146156
patch: `<> a solid:InsertDeletePatch;

0 commit comments

Comments
 (0)