Skip to content

Commit

Permalink
Item13571: (untested) fixes for Foswiki::UNICODE
Browse files Browse the repository at this point in the history
  • Loading branch information
Crawford Currie committed Jul 30, 2015
1 parent 53a0a5f commit 056bafc
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 77 deletions.
4 changes: 3 additions & 1 deletion data/System/FilesysVirtualPlugin.txt
@@ -1,4 +1,5 @@
%META:TOPICINFO{author="ProjectContributor" date="1356278771" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1425309996" format="1.1" version="1"}%
%META:TOPICPARENT{name="Plugins"}%
---+!! !FilesysVirtualPlugin
<!--
One line description, required for extensions repository catalog.
Expand Down Expand Up @@ -125,3 +126,4 @@ Many thanks to the following sponsors for supporting this work:
%META:FIELD{name="License" value="[[http://www.gnu.org/licenses/old-licenses/gpl-2.0.html][GPL2 (Gnu General Public License v2)]]"}%
%META:FIELD{name="Release" value="%$RELEASE%"}%
%META:FIELD{name="Version" value="%$VERSION%"}%
%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" date="1425309996" user="ProjectContributor" version="1"}%
56 changes: 29 additions & 27 deletions lib/Filesys/Virtual/Attachments.pm
Expand Up @@ -12,10 +12,10 @@ sub new {
my $class = shift;
my $args = shift;

my $this = bless($class->SUPER::new($args), $class);
my $this = bless( $class->SUPER::new($args), $class );

$Filesys::Virtual::Foswiki::FILES_EXT = '';
@Filesys::Virtual::Foswiki::views = ();
@Filesys::Virtual::Foswiki::views = ();

return $this;
}
Expand Down Expand Up @@ -53,56 +53,58 @@ sub _parseResource {
push( @path, $_ );
}
}

# strip off hidden attribute from filename
@path = map {$_ =~ s/^\.//; $_} @path if $this->{hideEmptyAttachmentDirs};
@path = map { $_ =~ s/^\.//; $_ } @path if $this->{hideEmptyAttachmentDirs};

# rebuild normalized resource
$resource = join("/", @path);
$resource = join( "/", @path );

# descend through webs
# descend through webs
my $web = '';
while ( scalar(@path)) {
last if $web && Foswiki::Func::topicExists($web,$path[0]);
$web .= ($web?'/':'') . shift(@path);
while ( scalar(@path) ) {
last if $web && Foswiki::Func::topicExists( $web, $path[0] );
$web .= ( $web ? '/' : '' ) . shift(@path);
}

my %info = (
type => 'R',
web => $web,
resource => $resource,
topic => shift(@path),
attachment => shift(@path),
type => 'R',
web => $web,
resource => $resource,
topic => shift(@path),
attachment => shift(@path),
);

# anything else is an error
return undef if scalar(@path);

# derive type from found resources and rebuild path
@path = ();
if ($info{web}) {
push @path, $info{web};
if ( $info{web} ) {
push @path, $info{web};

if ($info{topic}) {
push @path, $info{topic};
if ( $info{topic} ) {
push @path, $info{topic};

if ($info{attachment}) {
$info{type} = 'A';
push @path, $info{attachment};
} else {
$info{type} = 'D';
if ( $info{attachment} ) {
$info{type} = 'A';
push @path, $info{attachment};
}
else {
$info{type} = 'D';
}
}
else {
$info{type} = 'W';
}
} else {
$info{type} = 'W';
}
}

$info{path} = join("/", @path);
$info{path} = join( "/", @path );

#print STDERR dump(\%info)."\n";

return \%info;
}


1;

81 changes: 46 additions & 35 deletions lib/Filesys/Virtual/Foswiki.pm
Expand Up @@ -182,14 +182,15 @@ sub _initSession {
my $newPathInfo;
eval {
require Foswiki::Request;
my $request = new Foswiki::Request;
my $pathInfo = $request->path_info();
my $request = new Foswiki::Request;
my $pathInfo = $request->path_info();
my $davLocation = $Foswiki::cfg{Plugins}{WebDAVLinkPlugin}{Location};
if ( $pathInfo =~ /$davLocation\/(.+)\/(.+)_files/) {
if ( $pathInfo =~ /$davLocation\/(.+)\/(.+)_files/ ) {
$newPathInfo = "/$1/$2";
}
};
if ( $@ ) {
if ($@) {

# ignore...
}

Expand All @@ -204,34 +205,39 @@ sub _initSession {
# meyer@modell-aachen.de
# Possible fix for wrong/missing web and topic name
# Part 2
if ( $newPathInfo ) {
$this->{session}->{request}->pathInfo( $newPathInfo );
if ($newPathInfo) {
$this->{session}->{request}->pathInfo($newPathInfo);
}

# meyer@modell-aachen.de
# Add support for virtual hosting.
# See package VirtualHostingContrib for further details.
eval {
my $request = $this->{session}->{request};
my $host = $request->virtual_host();
my $port = $request->virtual_port();
my $host = $request->virtual_host();
my $port = $request->virtual_port();

require Foswiki::Contrib::VirtualHostingContrib::VirtualHost;
my $vhost = Foswiki::Contrib::VirtualHostingContrib::VirtualHost->find( $host, $port );

my $vconfig = $vhost->run( sub {
return {
PubDir => $Foswiki::cfg{PubDir},
WorkingDir => $Foswiki::cfg{WorkingDir},
DataDir => $Foswiki::cfg{DataDir},
};
} );
my $vhost =
Foswiki::Contrib::VirtualHostingContrib::VirtualHost->find( $host,
$port );

my $vconfig = $vhost->run(
sub {
return {
PubDir => $Foswiki::cfg{PubDir},
WorkingDir => $Foswiki::cfg{WorkingDir},
DataDir => $Foswiki::cfg{DataDir},
};
}
);

$Foswiki::cfg{PubDir} = $vconfig->{PubDir};
$Foswiki::cfg{PubDir} = $vconfig->{PubDir};
$Foswiki::cfg{WorkingDir} = $vconfig->{WorkingDir};
$Foswiki::cfg{DataDir} = $vconfig->{DataDir};
$Foswiki::cfg{DataDir} = $vconfig->{DataDir};
};
if ( $@ ) {
if ($@) {

# nothing...
}

Expand All @@ -240,13 +246,15 @@ sub _initSession {

# Convert one or more strings from perl logical characters to the site encoding
sub _logical2site {
return $@ if $Foswiki::UNICODE;
return
map { Encode::encode( $Foswiki::cfg{Site}{CharSet} || 'iso-8859-1', $_ ) }
@_;
}

# Convert one or more strings from the site encoding to perl logical characters
sub _site2logical {
return $@ if $Foswiki::UNICODE;
return
map { Encode::decode( $Foswiki::cfg{Site}{CharSet} || 'iso-8859-1', $_ ) }
@_;
Expand Down Expand Up @@ -518,7 +526,8 @@ sub _hasAttachments {
my ( $this, $web, $topic ) = @_;

if ( defined &Foswiki::Func::getAttachmentList ) {
my $num = grep { !/$this->{excludeAttachments}/ }
my $num =
grep { !/$this->{excludeAttachments}/ }
Foswiki::Func::getAttachmentList( $web, $topic );
return $num > 0;
}
Expand Down Expand Up @@ -565,12 +574,15 @@ sub _checkLock {
sub _checkName {
my ( $this, $info ) = @_;

# Foswiki uses internally coded names when checking
# validity of names, so we have to get back from the site charset
foreach my $key ( keys %{$info} ) {
$info->{$key} =
Encode::decode( $Foswiki::cfg{Site}{CharSet}, $info->{$key} )
if $info->{$key};
unless ($Foswiki::UNICODE) {

# Foswiki 1.x uses internally coded names when checking
# validity of names, so we have to get back from the site charset
foreach my $key ( keys %{$info} ) {
$info->{$key} =
Encode::decode( $Foswiki::cfg{Site}{CharSet}, $info->{$key} )
if $info->{$key};
}
}

if ( $info->{web} ) {
Expand Down Expand Up @@ -644,10 +656,7 @@ sub _getMode {
}
}

print STDERR "MODE /"
. ( $web || '' ) . "/"
. ( $topic || '' )
. "=$mode\n"
print STDERR "MODE /" . ( $web || '' ) . "/" . ( $topic || '' ) . "=$mode\n"
if ( $this->{trace} & 2 );
return $mode;
}
Expand Down Expand Up @@ -799,7 +808,7 @@ sub _A_delete {
}

my $destination =
"/"
"/"
. $Foswiki::cfg{TrashWebName}
. "/TrashAttachment$FILES_EXT/"
. $info->{attachment}
Expand All @@ -823,7 +832,7 @@ sub _T_delete {
}

my $destination =
"/"
"/"
. $Foswiki::cfg{TrashWebName} . '/'
. $info->{topic}
. $n
Expand Down Expand Up @@ -1271,7 +1280,8 @@ sub _D_list {
# list attachments
my @list = ();
if ( defined &Foswiki::Func::getAttachmentList ) {
@list = grep { !/$this->{excludeAttachments}/ }
@list =
grep { !/$this->{excludeAttachments}/ }
Foswiki::Func::getAttachmentList( $info->{web}, $info->{topic} );

# Have to include '.' and '..' to make it look like a dir
Expand Down Expand Up @@ -1747,7 +1757,8 @@ sub _A_open_read {
return $this->_fail( POSIX::EACCES, $info );
}

my $data = Foswiki::Func::readAttachment( $info->{web}, $info->{topic},
my $data =
Foswiki::Func::readAttachment( $info->{web}, $info->{topic},
$info->{attachment} );

return IO::String->new($data);
Expand Down
15 changes: 7 additions & 8 deletions lib/Filesys/Virtual/Locks.pm
Expand Up @@ -283,10 +283,10 @@ sub getLocks {
sub getAuthToken {
my ( $this, $token ) = @_;
my $auth = $this->{db}->{auth}->{$token};
if ( $auth ) {
if ($auth) {
my $now = scalar( time() );
return $auth if ( $auth->{expires} gt $now );
$this->removeAuthToken( $token );
$this->removeAuthToken($token);
}

return undef;
Expand All @@ -302,10 +302,11 @@ sub setAuthToken {
my $retval = 0;
$this->_lock();
eval {
if ( $data->{user} && $data->{path} && $data->{file} ) {
$data->{expires} = scalar( time() ) + 7200;
if ( $data->{user} && $data->{path} && $data->{file} )
{
$data->{expires} = scalar( time() ) + 7200;
$this->{db}->{auth}->{$token} = $data;
$retval = 1;
$retval = 1;
}
};

Expand All @@ -318,9 +319,7 @@ sub removeAuthToken {
my ( $this, $token ) = @_;

$this->_lock();
eval {
delete $this->{db}->{auth}->{$token};
};
eval { delete $this->{db}->{auth}->{$token}; };
$this->_unlock();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/FilesysVirtualPlugin/Views/raw.pm
Expand Up @@ -15,9 +15,9 @@ sub read {

my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
eval {
# 1.2 and later
# 2 and later
require Foswiki::Serialise;
$text = Foswiki::Serialise::serialise( $meta, 'Embedded');
$text = Foswiki::Serialise::serialise( $meta, 'Embedded' );
};
if ($@) {
$text = $meta->getEmbeddedStoreForm();
Expand Down
9 changes: 7 additions & 2 deletions test/unit/FilesysVirtualPlugin/FilesysVirtualFoswikiTests.pm
Expand Up @@ -144,7 +144,10 @@ HERE
sub _make_attachments_fixture {
my $this = shift;
foreach my $fn ( 'A.gif', 'B C.jpg', $extreme_attachment ) {
my $f = Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn );
my $f =
$Foswiki::UNICODE
? $fn
: Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn );
Foswiki::Func::saveAttachment( $this->{test_web}, $this->{test_topic},
$f, { file => "$tmpdir/testfile.gif" } );
$this->assert(
Expand Down Expand Up @@ -512,7 +515,9 @@ sub verify_delete_T {
Foswiki::Func::attachmentExists(
$Foswiki::cfg{TrashWebName},
"$this->{test_topic}$n",
Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn )
$Foswiki::UNICODE
? $fn
: Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn )
)
);
}
Expand Down
Expand Up @@ -144,7 +144,11 @@ HERE
sub _make_attachments_fixture {
my $this = shift;
foreach my $fn ( 'A.gif', 'B C.jpg', $extreme_attachment ) {
my $f = Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn );
my $f =
$Foswiki::UNICODE
? $fn
: Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn );

Foswiki::Func::saveAttachment( $this->{test_web}, $this->{test_topic},
$f, { file => "$tmpdir/testfile.gif" } );
$this->assert(
Expand Down Expand Up @@ -512,7 +516,9 @@ sub verify_delete_T {
Foswiki::Func::attachmentExists(
$Foswiki::cfg{TrashWebName},
"$this->{test_topic}$n",
Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn )
$Foswiki::UNICODE
? $fn
: Encode::encode( $Foswiki::cfg{Site}{CharSet}, $fn )
)
);
}
Expand Down

0 comments on commit 056bafc

Please sign in to comment.