diff options
author | Matthieu Moy <Matthieu.Moy@imag.fr> | 2012-11-29 18:00:55 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-11-29 11:16:33 -0800 |
commit | 462d97daf69951f968f16b6271de9db34f7dd13c (patch) | |
tree | 16cfb3a488e4790889ccb856d5b5ca63a2b1ccbb /contrib/mw-to-git/git-remote-mediawiki | |
parent | Start preparing for 1.8.0.2 (diff) | |
download | tgif-462d97daf69951f968f16b6271de9db34f7dd13c.tar.xz |
git-remote-mediawiki: escape ", \, and LF in file names
A mediawiki page can contain, and even start with a " character, we have
to escape it when generating the fast-export stream, as well as \
character. While we're there, also escape newlines, but I don't think we
can get them from MediaWiki pages.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/mw-to-git/git-remote-mediawiki')
-rwxr-xr-x | contrib/mw-to-git/git-remote-mediawiki | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki index 68555d4265..094129de09 100755 --- a/contrib/mw-to-git/git-remote-mediawiki +++ b/contrib/mw-to-git/git-remote-mediawiki @@ -711,6 +711,14 @@ sub fetch_mw_revisions { return ($n, @revisions); } +sub fe_escape_path { + my $path = shift; + $path =~ s/\\/\\\\/g; + $path =~ s/"/\\"/g; + $path =~ s/\n/\\n/g; + return '"' . $path . '"'; +} + sub import_file_revision { my $commit = shift; my %commit = %{$commit}; @@ -738,15 +746,17 @@ sub import_file_revision { print STDOUT "from refs/mediawiki/$remotename/master^0\n"; } if ($content ne DELETED_CONTENT) { - print STDOUT "M 644 inline $title.mw\n"; + print STDOUT "M 644 inline " . + fe_escape_path($title . ".mw") . "\n"; literal_data($content); if (%mediafile) { - print STDOUT "M 644 inline $mediafile{title}\n"; + print STDOUT "M 644 inline " + . fe_escape_path($mediafile{title}) . "\n"; literal_data_raw($mediafile{content}); } print STDOUT "\n\n"; } else { - print STDOUT "D $title.mw\n"; + print STDOUT "D " . fe_escape_path($title . ".mw") . "\n"; } # mediawiki revision number in the git note |