Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

uri_escape at directory-auto-index

  • Loading branch information...
commit 9da4e4b756af99bd716303757cf8f21e2372d0f1 1 parent b2c4aa2
@nihen nihen authored
View
3  lib/Plack/App/Directory.pm
@@ -6,6 +6,7 @@ use Plack::Util;
use HTTP::Date;
use Plack::MIME;
use DirHandle;
+use URI::Escape;
# Stolen from rack/directory.rb
my $dir_file = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>";
@@ -70,6 +71,8 @@ sub serve_path {
$url .= "/";
}
+ $url = join '/', map {uri_escape($_)} split m{/}, $url;
+
my $mime_type = $is_dir ? 'directory' : ( Plack::MIME->mime_type($file) || 'text/plain' );
push @files, [ $url, $basename, $stat[7], $mime_type, HTTP::Date::time2str($stat[9]) ];
}
View
0  share/#foo
No changes.
View
28 t/Plack-App/directory.t
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+use Test::More;
+use HTTP::Request::Common;
+use HTTP::Response;
+use Plack::Test;
+use Plack::App::Directory;
+
+my $handler = Plack::App::Directory->new({ root => 'share' });
+
+
+my %test = (
+ client => sub {
+ my $cb = shift;
+
+ {
+ # URI-escape
+ my $res = $cb->(GET "http://localhost/");
+ my($ct, $charset) = $res->content_type;
+ ok $res->content =~ m{/%23foo};
+ }
+},
+ app => $handler,
+);
+
+test_psgi %test;
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.