Fix UTF-8 handling in WebGUI::Storage class. Add tests for all methods that were checked. Fixes bug #12023.
This commit is contained in:
parent
889b2bc2fd
commit
49063cf526
3 changed files with 64 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
7.10.8
|
||||
- rfe #12016 for the top story as well
|
||||
- fixed #11965: Friend Manager only shows 15 people
|
||||
- fixed #12023: International URLs of aattachments & files in folder
|
||||
|
||||
7.10.7
|
||||
- rfe #10521: Use monospaced font in template edit textarea
|
||||
|
|
|
|||
|
|
@ -304,7 +304,10 @@ sub addFileFromFilesystem {
|
|||
if (! defined $pathToFile) {
|
||||
return undef;
|
||||
}
|
||||
##Handle UTF-8 filenames.
|
||||
$pathToFile = Encode::encode_utf8($pathToFile);
|
||||
$pathToFile = Cwd::realpath($pathToFile); # trace any symbolic links
|
||||
$pathToFile = Encode::decode_utf8($pathToFile);
|
||||
if (-d $pathToFile) {
|
||||
$self->session->log->error($pathToFile." is a directory, not a file.");
|
||||
return undef;
|
||||
|
|
@ -372,6 +375,7 @@ sub addFileFromFormPost {
|
|||
return $filename;
|
||||
}
|
||||
my $clientFilename = $upload->filename;
|
||||
$clientFilename = Encode::decode_utf8($clientFilename);
|
||||
next
|
||||
unless $clientFilename;
|
||||
next
|
||||
|
|
@ -1080,7 +1084,7 @@ sub getFiles {
|
|||
callback => sub {
|
||||
my $obj = shift;
|
||||
my $rel = $obj->relative($dir);
|
||||
my $str = $rel->stringify;
|
||||
my $str = Encode::decode_utf8($rel->stringify);
|
||||
if (! $showAll ) {
|
||||
return if $str =~ /^thumb-/;
|
||||
return if $str =~ /^\./;
|
||||
|
|
|
|||
58
t/Storage/utf8_filenames.t
Normal file
58
t/Storage/utf8_filenames.t
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#The goal of this test is to checkout uft8 handling in filenames.
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/..//lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Storage;
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Encode;
|
||||
use Cwd ();
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
my $storage = WebGUI::Storage->create($session);
|
||||
WebGUI::Test->addToCleanup($storage);
|
||||
|
||||
my $filename = "Viel_Spa\x{00DF}.txt";
|
||||
utf8::upgrade($filename);
|
||||
$storage->addFileFromScalar($filename, 'some content');
|
||||
ok -e $storage->getPath($filename), 'addFileFromScalar: wrote filename with UTF-8 name';
|
||||
|
||||
my $filesystem_storage = WebGUI::Storage->create($session);
|
||||
WebGUI::Test->addToCleanup($filesystem_storage);
|
||||
|
||||
$filesystem_storage->addFileFromFilesystem($storage->getPath($filename));
|
||||
ok -e $filesystem_storage->getPath($filename), 'addFileFromFilesystem: brought file over with UTF-8 name';
|
||||
|
||||
cmp_deeply(
|
||||
$filesystem_storage->getFiles(),
|
||||
[ $filename ],
|
||||
'getFiles: returns names in UTF-8'
|
||||
);
|
||||
|
||||
my $copy_name = "Ca\x{00F1}on.txt";
|
||||
utf8::upgrade($copy_name);
|
||||
$filesystem_storage->copyFile($filename, $copy_name);
|
||||
|
||||
cmp_bag(
|
||||
$filesystem_storage->getFiles(),
|
||||
[ $filename, $copy_name ],
|
||||
'copyFile: copies files handling UTF-8 correctly'
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue