git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] git-remote-mediawiki: fix encoding issue for UTF-8 media files

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Apr 23, 2014, 14:34 UTC
Message-ID
<1398263669-16594-2-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1398263669-16594-1-git-send-email-Matthieu.Moy@imag.fr>

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 <Matthieu.Moy@imag.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl          |  7 ++++++-
 contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 3f8d993..8dd74a9 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -461,7 +461,12 @@ sub download_mw_mediafile {
 
 	my $response = $mediawiki->{ua}->get($download_url);
 	if ($response->code == HTTP_CODE_OK) {
-		return $response->decoded_content;
+		# It is tempting to return
+		# $response->decoded_content({charset => "none"}), but
+		# when doing so, utf8::downgrade($content) fails with
+		# "Wide character in subroutine entry".
+		$response->decode();
+		return $response->content();
 	} else {
 		print {*STDERR} "Error downloading mediafile from :\n";
 		print {*STDERR} "URL: ${download_url}\n";
diff --git a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
index 5a03739..3ff3a09 100755
--- a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
+++ b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
@@ -58,6 +58,25 @@ test_expect_success 'git clone works on previously created wiki with media files
 	test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt
 '
 
+test_expect_success 'git push can upload media (File:) files containing valid UTF-8' '
+	wiki_reset &&
+	git clone mediawiki::'"$WIKI_URL"' mw_dir &&
+	(
+		cd mw_dir &&
+		"$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
+		git add Bar.txt &&
+		git commit -m "add a text file with UTF-8 content" &&
+		git push
+	)
+'
+
+test_expect_success 'git clone works on previously created wiki with media files containing valid UTF-8' '
+	test_when_finished "rm -rf mw_dir mw_dir_clone" &&
+	git clone -c remote.origin.mediaimport=true \
+		mediawiki::'"$WIKI_URL"' mw_dir_clone &&
+	test_cmp mw_dir_clone/Bar.txt mw_dir/Bar.txt
+'
+
 test_expect_success 'git push & pull work with locally renamed media files' '
 	wiki_reset &&
 	git clone mediawiki::'"$WIKI_URL"' mw_dir &&
-- 
1.9.2.667.ge5b74e1
Previous: Matthieu Moy
Message 2 of 2 in “git-remote-mediawiki: allow stop/start-ing the test server”
  1. 1/2 git-remote-mediawiki: allow stop/start-ing the test serverMatthieu Moy, Apr 23, 2014
  2. 2/2 git-remote-mediawiki: fix encoding issue for UTF-8 media filesMatthieu Moy, Apr 23, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.