Permalink
Browse files

Allow requests to files with non-ascii characters

(with URL encoded requests)
  • Loading branch information...
1 parent a400cff commit b29c84853c7cdfb312ac7d2beb8decab251bd7ec @mhansen committed Oct 17, 2010
Showing with 7 additions and 5 deletions.
  1. +3 −3 lib/antinode.js
  2. +2 −0 tests/fixtures/default-host/cyrillic_filename_Россия
  3. +2 −2 tests/test-200.js
View
@@ -86,9 +86,9 @@ function map_request_to_local_file(req, resp) {
var url = uri.parse(req.url);
//if the parsed url doesn't have a pathname, default to '/'
var pathname = (url.pathname || '/');
- var clean_pathname = pathname.
- replace(/\.\.\.*\/\/*/g,''). //disallow parent directory access
- replace(/\%20/g,' '); //convert spaces
+ var clean_pathname =
+ decodeURIComponent(pathname). // decode non-ascii chars, spaces, etc
+ replace(/\.\.\.*\/\/*/g,''); //disallow parent directory access
function select_vhost() {
if (req.headers.host) {
@@ -0,0 +1,2 @@
+This file has non-ascii characters in it - they need to be URL encoded in the
+request
View
@@ -1,6 +1,6 @@
require('./common');
-var files = ["smalltext", "dictionary", "cat.jpg", "oranga_thumb.jpg"];
+var files = ["smalltext", "dictionary", "cat.jpg", "oranga_thumb.jpg", "cyrillic_filename_Россия"];
files.forEach(function (file) {
var disc_filename = path.join(settings.default_host.root, file);
@@ -9,7 +9,7 @@ files.forEach(function (file) {
exports[file] = function(test) {
antinode.start(settings, function() {
test_http(test,
- {'method':'GET','pathname':'/'+file},
+ {'method':'GET','pathname':'/'+encodeURIComponent(file)},
{'statusCode':200,'body':fileText},
function() {
antinode.stop();

0 comments on commit b29c848

Please sign in to comment.