Skip to content

Commit 8a6a6f4

Browse files
committed
Merge branch 'maint'
* maint: git-fast-import.txt: improve documentation for quoted paths git-remote-mediawiki: escape ", \, and LF in file names
2 parents e7551a8 + 7c65b2e commit 8a6a6f4

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

Documentation/git-fast-import.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,12 @@ A `<path>` string must use UNIX-style directory separators (forward
562562
slash `/`), may contain any byte other than `LF`, and must not
563563
start with double quote (`"`).
564564

565-
If an `LF` or double quote must be encoded into `<path>` shell-style
566-
quoting should be used, e.g. `"path/with\n and \" in it"`.
565+
A path can use C-style string quoting; this is accepted in all cases
566+
and mandatory if the filename starts with double quote or contains
567+
`LF`. In C-style quoting, the complete name should be surrounded with
568+
double quotes, and any `LF`, backslash, or double quote characters
569+
must be escaped by preceding them with a backslash (e.g.,
570+
`"path/with\n, \\ and \" in it"`).
567571

568572
The value of `<path>` must be in canonical form. That is it must not:
569573

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,14 @@ sub fetch_mw_revisions {
711711
return ($n, @revisions);
712712
}
713713

714+
sub fe_escape_path {
715+
my $path = shift;
716+
$path =~ s/\\/\\\\/g;
717+
$path =~ s/"/\\"/g;
718+
$path =~ s/\n/\\n/g;
719+
return '"' . $path . '"';
720+
}
721+
714722
sub import_file_revision {
715723
my $commit = shift;
716724
my %commit = %{$commit};
@@ -738,15 +746,17 @@ sub import_file_revision {
738746
print STDOUT "from refs/mediawiki/$remotename/master^0\n";
739747
}
740748
if ($content ne DELETED_CONTENT) {
741-
print STDOUT "M 644 inline $title.mw\n";
749+
print STDOUT "M 644 inline " .
750+
fe_escape_path($title . ".mw") . "\n";
742751
literal_data($content);
743752
if (%mediafile) {
744-
print STDOUT "M 644 inline $mediafile{title}\n";
753+
print STDOUT "M 644 inline "
754+
. fe_escape_path($mediafile{title}) . "\n";
745755
literal_data_raw($mediafile{content});
746756
}
747757
print STDOUT "\n\n";
748758
} else {
749-
print STDOUT "D $title.mw\n";
759+
print STDOUT "D " . fe_escape_path($title . ".mw") . "\n";
750760
}
751761

752762
# mediawiki revision number in the git note

contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,30 @@ test_expect_success 'git push with \ in format control' '
318318
'
319319

320320

321+
test_expect_success 'fast-import meta-characters in page name (mw -> git)' '
322+
wiki_reset &&
323+
wiki_editpage \"file\"_\\_foo "expect to be called \"file\"_\\_foo" false &&
324+
git clone mediawiki::'"$WIKI_URL"' mw_dir_21 &&
325+
test_path_is_file mw_dir_21/\"file\"_\\_foo.mw &&
326+
wiki_getallpage ref_page_21 &&
327+
test_diff_directories mw_dir_21 ref_page_21
328+
'
329+
330+
331+
test_expect_success 'fast-import meta-characters in page name (git -> mw) ' '
332+
wiki_reset &&
333+
git clone mediawiki::'"$WIKI_URL"' mw_dir_22 &&
334+
(
335+
cd mw_dir_22 &&
336+
echo "this file is called \"file\"_\\_foo.mw" >\"file\"_\\_foo &&
337+
git add . &&
338+
git commit -am "file \"file\"_\\_foo" &&
339+
git pull &&
340+
git push
341+
) &&
342+
wiki_getallpage ref_page_22 &&
343+
test_diff_directories mw_dir_22 ref_page_22
344+
'
345+
346+
321347
test_done

0 commit comments

Comments
 (0)