Skip to content

Commit 9742fb7

Browse files
moygitster
authored andcommitted
git-remote-mediawiki: fix encoding issue for UTF-8 media files
When a media file contains valid UTF-8, git-remote-mediawiki tried to be too clever about the encoding, and the call to utf8::downgrade() on the downloaded content was failing with Wide character in subroutine entry at git-remote-mediawiki line 583. Instead, use $response->decode() to apply decoding linked to the Content-Encoding: header, and return the content without attempting any charset decoding. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c4ea83 commit 9742fb7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

contrib/mw-to-git/git-remote-mediawiki.perl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,12 @@ sub download_mw_mediafile {
461461

462462
my $response = $mediawiki->{ua}->get($download_url);
463463
if ($response->code == HTTP_CODE_OK) {
464-
return $response->decoded_content;
464+
# It is tempting to return
465+
# $response->decoded_content({charset => "none"}), but
466+
# when doing so, utf8::downgrade($content) fails with
467+
# "Wide character in subroutine entry".
468+
$response->decode();
469+
return $response->content();
465470
} else {
466471
print {*STDERR} "Error downloading mediafile from :\n";
467472
print {*STDERR} "URL: ${download_url}\n";

contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ test_expect_success 'git clone works on previously created wiki with media files
5858
test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt
5959
'
6060

61+
test_expect_success 'git push can upload media (File:) files containing valid UTF-8' '
62+
wiki_reset &&
63+
git clone mediawiki::'"$WIKI_URL"' mw_dir &&
64+
(
65+
cd mw_dir &&
66+
"$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
67+
git add Bar.txt &&
68+
git commit -m "add a text file with UTF-8 content" &&
69+
git push
70+
)
71+
'
72+
73+
test_expect_success 'git clone works on previously created wiki with media files containing valid UTF-8' '
74+
test_when_finished "rm -rf mw_dir mw_dir_clone" &&
75+
git clone -c remote.origin.mediaimport=true \
76+
mediawiki::'"$WIKI_URL"' mw_dir_clone &&
77+
test_cmp mw_dir_clone/Bar.txt mw_dir/Bar.txt
78+
'
79+
6180
test_expect_success 'git push & pull work with locally renamed media files' '
6281
wiki_reset &&
6382
git clone mediawiki::'"$WIKI_URL"' mw_dir &&

0 commit comments

Comments
 (0)