Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Handle spaces in paths in fs-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Jun 9, 2015
1 parent 5cfc05b commit 78b7a80
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
47 changes: 32 additions & 15 deletions hydrolysis.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/loader/fs-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ FSResolver.prototype = {
accept: function(uri, deferred) {
var parsed = url.parse(uri);
var host = this.config.host;
var base = this.config.basePath;
var base = this.config.basePath && decodeURIComponent(this.config.basePath);
var root = this.config.root && path.normalize(this.config.root);
var redirect = this.config.redirect;

Expand All @@ -79,6 +79,9 @@ FSResolver.prototype = {
}

if (local) {
// un-escape HTML escapes
local = decodeURIComponent(local);

if (base) {
local = path.relative(base, local);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"watch": "latest"
},
"dependencies": {
"dom5": "^1.0.3",
"dom5": "^1.1.0",
"es6-promise": "^2.1.0",
"espree": "^2.0.1",
"estraverse": "^3.1.0",
Expand Down
1 change: 1 addition & 0 deletions test/static/spaces in request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Spaces!
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ suite('Loader', function() {
assert.equal(content.trim(), 'Hello!');
}).then(done, done);
});

test('Spaces in Filepath', function(done) {
var fs = new fsResolver({
root: path.join(__dirname, '..')
});
l.addResolver(fs);
l.request('/test/static/spaces%20in%20request.txt').then(function(content) {
assert.equal(content.trim(), 'Spaces!');
}).then(done, done);
});

test('Spaces in Filepath', function(done) {
var fs = new fsResolver({
root: path.join(__dirname, '..'),
basePath: '/space%20in%20basePath'
});
l.addResolver(fs);
l.request('/space%20in%20basePath/test/static/xhr-text.txt').then(function(content) {
assert.equal(content.trim(), 'Hello!');
}).then(done, done);
});
});

suite('Noop Resolver', function() {
Expand Down

0 comments on commit 78b7a80

Please sign in to comment.