@@ -5,15 +5,16 @@ const debug = require('debug')('solid:put')
55const getContentType = require ( '../utils' ) . getContentType
66const HTTPError = require ( '../http-error' )
77const { stringToStream } = require ( '../utils' )
8- const LDP = require ( '../ldp' )
98
109async function handler ( req , res , next ) {
1110 debug ( req . originalUrl )
1211 res . header ( 'MS-Author-Via' , 'SPARQL' )
1312
1413 const contentType = req . get ( 'content-type' )
15- if ( LDP . mimeTypeIsRdf ( contentType ) && isAclFile ( req ) ) {
16- return bodyParser . text ( { type : ( ) => true } ) ( req , res , ( ) => putAcl ( req , res , next ) )
14+ if ( isAuxiliary ( req ) ) {
15+ if ( contentType === 'text/turtle' ) {
16+ return bodyParser . text ( { type : ( ) => true } ) ( req , res , ( ) => putAuxiliary ( req , res , next ) )
17+ } else return next ( new HTTPError ( 415 , 'RDF file contains invalid syntax' ) )
1718 }
1819 return putStream ( req , res , next )
1920}
@@ -34,7 +35,9 @@ async function putStream (req, res, next, stream = req) {
3435 }
3536}
3637
37- function putAcl ( req , res , next ) {
38+ // needed to avoid breaking access with bad acl
39+ // or breaking containement triples for meta
40+ function putAuxiliary ( req , res , next ) {
3841 const ldp = req . app . locals . ldp
3942 const contentType = req . get ( 'content-type' )
4043 const requestUri = ldp . resourceMapper . getRequestUrl ( req )
@@ -46,7 +49,8 @@ function putAcl (req, res, next) {
4649 next ( new HTTPError ( 400 , 'RDF file contains invalid syntax' ) )
4750}
4851
49- function isAclFile ( req ) {
52+ function isAuxiliary ( req ) {
5053 const originalUrlParts = req . originalUrl . split ( '.' )
51- return originalUrlParts [ originalUrlParts . length - 1 ] === 'acl'
54+ const ext = originalUrlParts [ originalUrlParts . length - 1 ]
55+ return ( ext === 'acl' || ext === 'meta' )
5256}
0 commit comments