@@ -17,6 +17,7 @@ const ldpContainer = require('./ldp-container')
1717const parse = require ( './utils' ) . parse
1818const fetch = require ( 'node-fetch' )
1919const { promisify } = require ( 'util' )
20+ const URI = require ( 'urijs' )
2021
2122const DEFAULT_CONTENT_TYPE = 'text/turtle'
2223
@@ -263,7 +264,7 @@ class LDP {
263264 const filePath = utils . uriToFilename ( resourcePath , root , host )
264265
265266 // PUT requests not supported on containers. Use POST instead
266- if ( filePath . endsWith ( '/' ) ) {
267+ if ( resourcePath . endsWith ( '/' ) ) {
267268 return callback ( error ( 409 ,
268269 'PUT not supported on containers, use POST instead' ) )
269270 }
@@ -420,6 +421,11 @@ class LDP {
420421 return callback ( error ( err , 'Can\'t find file requested: ' + filename ) )
421422 }
422423
424+ // windows does not differentiate between file paths with or without trailing slash
425+ if ( reqPath . substr ( - 1 ) === '/' && ! stats . isDirectory ( ) ) {
426+ return callback ( error ( 404 , 'Can\'t find directory requested: ' + filename ) )
427+ }
428+
423429 // Just return, since resource exists
424430 if ( ! includeBody ) {
425431 return callback ( null , { 'stream' : stats , 'contentType' : contentType , 'container' : stats . isDirectory ( ) } )
@@ -540,13 +546,13 @@ class LDP {
540546 // Verify whether the new path already exists
541547 return self . exists ( host , newPath ) . then (
542548 // If it does, generate another one
543- ( ) => ensureNotExists ( self , path . join ( containerURI ,
544- `${ uuid . v1 ( ) . split ( '-' ) [ 0 ] } -${ filename } ` ) ) ,
549+ ( ) => ensureNotExists ( self , URI . joinPaths ( containerURI ,
550+ `${ uuid . v1 ( ) . split ( '-' ) [ 0 ] } -${ filename } ` ) . toString ( ) ) ,
545551 // If not, we found an appropriate path
546552 ( ) => newPath
547553 )
548554 }
549- return ensureNotExists ( this , path . join ( containerURI , filename ) )
555+ return ensureNotExists ( this , URI . joinPaths ( containerURI , filename ) . toString ( ) )
550556 }
551557}
552558module . exports = LDP
0 commit comments