Skip to content

Commit d56cdf0

Browse files
committed
only for containers
1 parent 51163e9 commit d56cdf0

File tree

4 files changed

+86
-362
lines changed

4 files changed

+86
-362
lines changed

lib/ldp.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,24 @@ class LDP {
145145

146146
const ldp = this
147147
debug.handlers('POST -- On parent: ' + containerPath)
148-
// prepare slug
148+
if (container) {
149+
// Containers should not receive an extension
150+
extension = ''
151+
}
152+
// pepare slug
149153
if (slug) {
150-
if (this.isAuxResource(slug, extension)) throw error(403, 'POST is not allowed for auxiliary resources')
151-
if (this._containsInvalidSuffixes(slug)) {
152-
throw error(400, `${slug} is an invalid file path`)
153-
}
154154
slug = decodeURIComponent(slug)
155+
156+
if (container) {
157+
// the name of a container cannot be a valid auxiliary resource document
158+
if (this._containsInvalidSuffixes(slug + '/')) slug = slug.split('.')[0]
159+
} else if (this.isAuxResource(slug, extension)) throw error(403, 'POST is not allowed for auxiliary resources')
160+
155161
if (slug.match(/\/|\||:/)) {
156162
throw error(400, 'The name of new file POSTed may not contain : | or /')
157163
}
158164
}
159165

160-
// Containers should not receive an extension
161-
if (container) {
162-
extension = ''
163-
}
164-
165166
// always return a valid URL.
166167
const resourceUrl = await ldp.getAvailableUrl(hostname, containerPath, { slug, extension, container })
167168
debug.handlers('POST -- Will create at: ' + resourceUrl)
@@ -338,17 +339,7 @@ class LDP {
338339
* @returns {boolean} true is fail - if the path contains reserved suffixes
339340
*/
340341
_containsInvalidSuffixes (path) {
341-
// if it is a container, no suffix so remove last slash
342-
if (path.endsWith('/')) {
343-
path = path.slice(0, -1)
344-
} else {
345-
// this is a resource, so it either ends with an extension, or just text
346-
const lastFullStop = path.lastIndexOf('.')
347-
if (lastFullStop !== -1) { // contains at least one full stop
348-
path = path.slice(0, lastFullStop)
349-
}
350-
}
351-
return AUXILIARY_RESOURCES.some(suffix => path.includes(suffix))
342+
return AUXILIARY_RESOURCES.some(suffix => path.endsWith(suffix + '/'))
352343
}
353344

354345
// check whether a document (or container) has the same name as another document (or container)

0 commit comments

Comments
 (0)