git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-remote-mediawiki: escape double quotes and LF in file names
@ 2012-11-29 12:33 Matthieu Moy
  2012-11-29 16:25 ` Junio C Hamano
  0 siblings, 1 reply; 16+ messages in thread
From: Matthieu Moy @ 2012-11-29 12:33 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy

A mediawiki page can contain, and even start with a " character, we have
to escape it when generating the fast-export stream. 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>
---
 contrib/mw-to-git/git-remote-mediawiki | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index 68555d4..e7a0e7b 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -711,6 +711,13 @@ sub fetch_mw_revisions {
 	return ($n, @revisions);
 }
 
+sub fe_escape_path {
+    my $path = shift;
+    $path =~ s/"/\\"/g;
+    $path =~ s/\n/\\n/g;
+    return $path;
+}
+
 sub import_file_revision {
 	my $commit = shift;
 	my %commit = %{$commit};
@@ -738,15 +745,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
-- 
1.8.0.319.g8abfee4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-12-02  2:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-29 12:33 [PATCH] git-remote-mediawiki: escape double quotes and LF in file names Matthieu Moy
2012-11-29 16:25 ` Junio C Hamano
2012-11-29 16:57   ` Matthieu Moy
2012-11-29 17:00     ` [PATCH 1/2] git-fast-import.txt: improve documentation for quoted paths Matthieu Moy
2012-11-29 17:00       ` [PATCH 2/2 v2] git-remote-mediawiki: escape ", \, and LF in file names Matthieu Moy
2012-11-29 18:11       ` [PATCH 1/2] git-fast-import.txt: improve documentation for quoted paths Jeff King
2012-11-29 18:47         ` Matthieu Moy
2012-11-29 18:54           ` Jeff King
2012-11-29 19:11             ` [PATCH 1/2 v3] " Matthieu Moy
2012-11-29 19:11               ` [PATCH 2/2 v3] git-remote-mediawiki: escape ", \, and LF in file names Matthieu Moy
2012-11-29 19:33               ` [PATCH 1/2 v3] git-fast-import.txt: improve documentation for quoted paths Junio C Hamano
2012-11-29 19:46                 ` Jeff King
2012-11-29 19:15         ` [PATCH 1/2] " Junio C Hamano
2012-11-29 19:19           ` Jeff King
2012-11-30  9:39           ` Matthieu Moy
2012-12-02  2:27             ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).