Skip to content

Instantly share code, notes, and snippets.

@gypark
Forked from aero/patch.diff
Created March 30, 2013 15:36
Show Gist options
  • Save gypark/5277129 to your computer and use it in GitHub Desktop.
Save gypark/5277129 to your computer and use it in GitHub Desktop.
--- Directory.pm.org 2012-11-12 13:38:22.000000000 +0900
+++ Directory.pm 2013-03-31 00:23:52.000000000 +0900
@@ -5,6 +5,7 @@
use Cwd ();
use Encode ();
+use Encode::Locale;
use DirHandle;
use Mojo::Base qw{ Mojolicious::Plugin };
use Mojolicious::Types;
@@ -12,6 +13,7 @@
# Stolen from Plack::App::Direcotry
my $dir_page = <<'PAGE';
<html><head>
+ % $cur_path = Encode::decode('locale', $cur_path);
<title>Index of <%= $cur_path %></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type='text/css'>
@@ -98,10 +100,10 @@
: ( { url => '../', name => 'Parent Directory', size => '', type => '', mtime => '' } );
my $children = list_files($dir);
- my $cur_path = Encode::decode_utf8( Mojo::Util::url_unescape( $c->req->url->path ) );
+ my $cur_path = Mojo::Util::url_unescape( $c->req->url->path );
for my $basename ( sort { $a cmp $b } @$children ) {
my $file = "$dir/$basename";
- my $url = Mojo::Path->new($cur_path)->trailing_slash(0);
+ my $url = Mojo::Path->new($cur_path)->charset(undef)->trailing_slash(0);
push @{ $url->parts }, $basename;
my $is_dir = -d $file;
@@ -119,7 +121,7 @@
push @files, {
url => $url,
- name => $basename,
+ name => Encode::decode('locale', $basename),
size => $stat[7] || 0,
type => $mime_type,
mtime => $mtime,
@@ -140,7 +142,7 @@
my @children;
while ( defined( my $ent = $dh->read ) ) {
next if $ent eq '.' or $ent eq '..';
- push @children, Encode::decode_utf8($ent);
+ push @children, $ent;
}
return [ @children ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment