From d4edb159ae1318fd934dadbdec2af2a7d6e6e00a Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Wed, 25 Jul 2012 13:42:22 +0200 Subject: [PATCH 1/2] Use binmode to set stdout to raw when printing uploaded files. The bug involved uploaded images not being decoded correctly. --- wiki.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/wiki.pl b/wiki.pl index 6ce55b97..7bfb876a 100755 --- a/wiki.pl +++ b/wiki.pl @@ -3132,6 +3132,7 @@ sub DoDownload { if @UploadTypes and not $allowed{$type}; print GetHttpHeader($type, $ts, undef, $encoding); require MIME::Base64; + binmode(STDOUT, "raw"); print MIME::Base64::decode($data); } else { print GetHttpHeader('text/plain', $ts); From ce183771099d9c7c5d94fa8416721fcfb6e5d9b0 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Mon, 30 Jul 2012 18:14:29 +0200 Subject: [PATCH 2/2] Use utf8::decode on filenames passed to PageIsUploadedFile Without this, search will break on pagenames with non-ASCII characters. I noted this in conjunction with tags.pl. There, I needed to encode the page names for search to work correctly. --- modules/tags.pl | 5 ++--- wiki.pl | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/tags.pl b/modules/tags.pl index a7a9c92d..947fe46f 100644 --- a/modules/tags.pl +++ b/modules/tags.pl @@ -218,6 +218,7 @@ sub TagFind { my %page; foreach my $tag (@tags) { foreach my $id (split(/$FS/, $h{lc($tag)})) { + utf8::decode($id); $page{$id} = 1; } } @@ -248,9 +249,7 @@ sub NewTagGrepFiltered { # called within a lock! } # filter out the tags from the search string $string = join(' ', grep(!/^-?tag:/, $string =~ /\"([^\"]+)\"|(\S+)/g)); - # if no query terms remain, just return the pages we found - # return sort keys %page if $string eq ''; - # otherwise run grep + # run the old code for any remaining search terms return OldTagGrepFiltered($string, sort keys %page); } diff --git a/wiki.pl b/wiki.pl index 7bfb876a..066649cb 100755 --- a/wiki.pl +++ b/wiki.pl @@ -2797,7 +2797,7 @@ sub ExpireKeepFiles { # call with opened page sub ReadFile { my $file = shift; - utf8::encode($file); + utf8::encode($file); # filenames are bytes! if (open(IN, '<:encoding(UTF-8)', $file)) { local $/ = undef; # Read complete files my $data=; @@ -3371,6 +3371,7 @@ sub PageIsUploadedFile { return undef if $OpenPageName eq $id; if ($IndexHash{$id}) { my $file = GetPageFile($id); + utf8::encode($file); # filenames are bytes! open(FILE, '<:encoding(UTF-8)', $file) or ReportError(Ts('Cannot open %s', $file) . ": $!", '500 INTERNAL SERVER ERROR'); while (defined($_ = ) and $_ !~ /^text: /) {