Skip to content

Commit 364be6b

Browse files
author
jaxoncreed
committed
Resource mapper properly encodes special characters in the uri
1 parent 7ca978d commit 364be6b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/resource-mapper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ class ResourceMapper {
7878

7979
// Determine the URL by chopping off everything after the dollar sign
8080
const pathname = this._removeDollarExtension(path)
81-
const url = `${this.resolveUrl(hostname)}${encodeURI(pathname)}`
81+
console.log(pathname)
82+
const url = `${this.resolveUrl(hostname)}${
83+
pathname.split('/').map((component) => encodeURIComponent(component)).join('/')
84+
}`
8285
return { url, contentType: this._getContentTypeByExtension(path) }
8386
}
8487

test/unit/resource-mapper-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,13 @@ describe('ResourceMapper', () => {
478478
url: 'http://localhost/space/foo%20bar%20bar.html',
479479
contentType: 'text/html'
480480
})
481+
482+
itMapsFile(mapper, 'a file with even stranger disallowed IRI characters',
483+
{ path: `${rootPath}space/Blog discovery for the future? · Issue #96 · scripting:Scripting-News · GitHub.pdf` },
484+
{
485+
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',
486+
contentType: 'application/pdf'
487+
})
481488
})
482489

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

0 commit comments

Comments
 (0)