Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enables FileServer to serve files with spaces in paths. Closes #14

  • Loading branch information...
commit f59e4ff174915ee0e699e838ef1ad5c326517e9b 1 parent 720e924
Seth Purcell authored
View
1  .gitignore
@@ -1 +1,2 @@
.idea
+node_modules
View
3  lib/stages/FileServer.js
@@ -75,10 +75,9 @@ var FileServer = Stage.extend({
service: function(request) {
var t = this;
- var reqPath = request.path;
+ var reqPath = decodeURI(request.path);
// bounce potentially malicious paths - not very sophisticated; could be legal
- // todo do we need to decodeURIComponent request.url or does node do that?
if (reqPath.indexOf('..') >= 0) {
throw new capsela.Error("can't use .. in path", 403);
}
View
25 testing/tests/stages/FileServerTest.js
@@ -146,6 +146,31 @@ exports["basics"] = {
).done();
},
+ "test URL with encoded spaces matches": function(test) {
+
+ var fileServer = new FileServer("/", testbench.fixturesDir + '/fileserver4');
+ var request = new Request('GET', "/i'm a dirname!/oh dear.html");
+ var bodyBuffer = new Pipe(true);
+ var contentLength;
+
+ Q.when(fileServer.service(request),
+ function(response) {
+ test.equal(response.statusCode, 200);
+ contentLength = response.getHeader('content-length');
+ test.equal(response.getHeader("Content-Type"), "text/html");
+ test.equal(response.getHeader('Expires'), new Date(now + 365 * 86400 * 1000).toUTCString());
+ response.sendBody(bodyBuffer);
+ return bodyBuffer.getData();
+ }
+ ).then(
+ function(data) {
+ test.ok(data.toString().indexOf('<p>chickens</p>') > 0);
+ test.equal(data.length, contentLength);
+ test.done();
+ }
+ ).done();
+ },
+
"test missing file falls through": function(test) {
var fileServer = new FileServer("/", testbench.fixturesDir + '/fileserver');
Please sign in to comment.
Something went wrong with that request. Please try again.