@@ -145,23 +145,24 @@ class LDP {
145
145
146
146
const ldp = this
147
147
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
149
153
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
- }
154
154
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
+
155
161
if ( slug . match ( / \/ | \| | : / ) ) {
156
162
throw error ( 400 , 'The name of new file POSTed may not contain : | or /' )
157
163
}
158
164
}
159
165
160
- // Containers should not receive an extension
161
- if ( container ) {
162
- extension = ''
163
- }
164
-
165
166
// always return a valid URL.
166
167
const resourceUrl = await ldp . getAvailableUrl ( hostname , containerPath , { slug, extension, container } )
167
168
debug . handlers ( 'POST -- Will create at: ' + resourceUrl )
@@ -338,17 +339,7 @@ class LDP {
338
339
* @returns {boolean } true is fail - if the path contains reserved suffixes
339
340
*/
340
341
_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 + '/' ) )
352
343
}
353
344
354
345
// check whether a document (or container) has the same name as another document (or container)
0 commit comments