Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/resource-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { promisify } = require('util')
const { types, extensions } = require('mime-types')
const readdir = promisify(fs.readdir)
const HTTPError = require('./http-error')
const pathUtil = require('path')

/*
* A ResourceMapper maintains the mapping between HTTP URLs and server filenames,
Expand Down Expand Up @@ -78,7 +79,9 @@ class ResourceMapper {

// Determine the URL by chopping off everything after the dollar sign
const pathname = this._removeDollarExtension(path)
const url = `${this.resolveUrl(hostname)}${encodeURI(pathname)}`
const url = `${this.resolveUrl(hostname)}${
pathname.split(pathUtil.sep).map((component) => encodeURIComponent(component)).join('/')
}`
return { url, contentType: this._getContentTypeFromExtension(path) }
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/resource-mapper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ describe('ResourceMapper', () => {
url: 'http://localhost/space/foo%20bar%20bar.html',
contentType: 'text/html'
})

itMapsFile(mapper, 'a file with even stranger disallowed IRI characters',
{ path: `${rootPath}space/Blog discovery for the future? · Issue #96 · scripting:Scripting-News · GitHub.pdf` },
{
url: 'http://localhost/space/Blog%20discovery%20for%20the%20future%3F%20%C2%B7%20Issue%20%2396%20%C2%B7%20scripting%3AScripting-News%20%C2%B7%20GitHub.pdf',
contentType: 'application/pdf'
})
})

describe('A ResourceMapper instance for a multi-host setup', () => {
Expand Down