@@ -145,18 +145,26 @@ 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
154
slug = decodeURIComponent ( slug )
155
+
156
+ if ( container ) {
157
+ // the name of a container cannot be a valid auxiliary resource document
158
+ while ( this . _containsInvalidSuffixes ( slug + '/' ) ) {
159
+ const idx = slug . lastIndexOf ( '.' )
160
+ slug = slug . substr ( 0 , idx )
161
+ }
162
+ } else if ( this . isAuxResource ( slug , extension ) ) throw error ( 403 , 'POST to auxiliary resources is not allowed' )
163
+
152
164
if ( slug . match ( / \/ | \| | : / ) ) {
153
- throw error ( 400 , 'The name of new file POSTed may not contain : | or / ' )
165
+ throw error ( 400 , 'The name of a POSTed new file may not contain ":" (colon), "|" (pipe), or "/" (slash) ' )
154
166
}
155
167
}
156
- // Containers should not receive an extension
157
- if ( container ) {
158
- extension = ''
159
- }
160
168
161
169
// always return a valid URL.
162
170
const resourceUrl = await ldp . getAvailableUrl ( hostname , containerPath , { slug, extension, container } )
@@ -327,11 +335,25 @@ class LDP {
327
335
} catch ( err ) { }
328
336
}
329
337
338
+ /**
339
+ * This function is used to make sure a resource or container which contains
340
+ * reserved suffixes for auxiliary documents cannot be created.
341
+ * @param {string } path - the uri to check for invalid suffixes
342
+ * @returns {boolean } true is fail - if the path contains reserved suffixes
343
+ */
344
+ _containsInvalidSuffixes ( path ) {
345
+ return AUXILIARY_RESOURCES . some ( suffix => path . endsWith ( suffix + '/' ) )
346
+ }
347
+
330
348
// check whether a document (or container) has the same name as another document (or container)
331
349
async checkItemName ( url ) {
332
350
let testName , testPath
333
351
const { hostname, pathname } = this . resourceMapper . _parseUrl ( url ) // (url.url || url)
334
352
let itemUrl = this . resourceMapper . resolveUrl ( hostname , pathname )
353
+ // make sure the resource being created does not attempt invalid resource creation
354
+ if ( this . _containsInvalidSuffixes ( itemUrl ) ) {
355
+ throw error ( 400 , `${ itemUrl } contained reserved suffixes in path` )
356
+ }
335
357
const container = itemUrl . endsWith ( '/' )
336
358
try {
337
359
const testUrl = container ? itemUrl . slice ( 0 , - 1 ) : itemUrl + '/'
0 commit comments