Skip to content

Commit ea39156

Browse files
authored
Merge pull request #1052 from solid/fix/put-validate-request-uri
Fix that should create a correct base URI wrt validation when PUTing TTL-files
2 parents 915e632 + 0affe08 commit ea39156

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/handlers/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function globHandler (req, res, next) {
134134
const ldp = req.app.locals.ldp
135135
// TODO: This is a hack, that does not check if the target file exists, as this is quite complex with globbing.
136136
// TODO: Proper support for this is not implemented, as globbing support might be removed in the future.
137-
const filename = ldp.resourceMapper._getFullPath(req)
137+
const filename = ldp.resourceMapper.getFullPath(req)
138138
const requestUri = (await ldp.resourceMapper.mapFileToUrl({ path: filename, hostname: req.hostname })).url
139139

140140
const globOptions = {

lib/handlers/put.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ async function putStream (req, res, next, stream = req) {
3636
async function putAcl (req, res, next) {
3737
const ldp = req.app.locals.ldp
3838
const contentType = req.get('content-type')
39-
const requestUri = `${req.protocol}//${req.get('host')}${req.originalUrl}`
39+
const path = ldp.resourceMapper.getFullPath(req)
40+
const requestUri = await ldp.resourceMapper.resolveUrl(req.hostname, path)
4041
if (ldp.isValidRdf(req.body, requestUri, contentType)) {
4142
const stream = stringToStream(req.body)
4243
return putStream(req, res, next, stream)

lib/resource-mapper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ResourceMapper {
4242
// When the URL ends with a '/', then files with the prefix 'index.' will be matched,
4343
// such as 'index.html' and 'index.ttl', unless searchIndex is false.
4444
async mapUrlToFile ({ url, contentType, createIfNotExists, searchIndex = true }) {
45-
let fullPath = this._getFullPath(url)
45+
let fullPath = this.getFullPath(url)
4646
let isIndex = searchIndex && fullPath.endsWith('/')
4747
let path
4848

@@ -111,7 +111,7 @@ class ResourceMapper {
111111
}
112112

113113
// Determine the full file path corresponding to a URL
114-
_getFullPath (url) {
114+
getFullPath (url) {
115115
const { pathname, hostname } = this._parseUrl(url)
116116
const fullPath = decodeURIComponent(`${this.getBasePath(hostname)}${pathname}`)
117117
if (fullPath.indexOf('/..') >= 0) {

0 commit comments

Comments
 (0)