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

Re: [PATCH] git-remote-mediawiki: escape double quotes and LF in file names

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 29, 2012, 16:25 UTC
Message-ID
<7vy5hkqsut.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1354192413-9959-1-git-send-email-Matthieu.Moy@imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 24 quoted lines
> 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;
> +}
Is this sufficient?

My reading of the big comment at the beginning of fast-import.c is that you would also want to quote each backslash; otherwise a character (or an octal) after it will be taken as a C-style quoted special letter, no?

Show 24 quoted lines
>  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
Previous: Matthieu MoyNext: Matthieu Moy
Message 2 of 16 in “git-remote-mediawiki: escape double quotes and LF in file names”
  1. git-remote-mediawiki: escape double quotes and LF in file namesMatthieu Moy, Nov 29, 2012
  2. Junio C HamanoNov 29, 2012
  3. Matthieu MoyNov 29, 2012
  4. 1/2 git-fast-import.txt: improve documentation for quoted pathsMatthieu Moy, Nov 29, 2012
  5. 2/2 git-remote-mediawiki: escape ", \, and LF in file namesMatthieu Moy, Nov 29, 2012
  6. Jeff KingNov 29, 2012
  7. Matthieu MoyNov 29, 2012
  8. Jeff KingNov 29, 2012
  9. 1/2 git-fast-import.txt: improve documentation for quoted pathsMatthieu Moy, Nov 29, 2012
  10. 2/2 git-remote-mediawiki: escape ", \, and LF in file namesMatthieu Moy, Nov 29, 2012
  11. Junio C HamanoNov 29, 2012
  12. Jeff KingNov 29, 2012
  13. Junio C HamanoNov 29, 2012
  14. Jeff KingNov 29, 2012
  15. Matthieu MoyNov 30, 2012
  16. Junio C HamanoDec 2, 2012

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.