#!/usr/bin/perl
BEGIN {
use_ok(
'Dpkg::Source::Patch'
);
}
my
$datadir
= test_get_data_path();
my
$tmpdir
= test_get_temp_path();
sub
test_patch_escape {
my
(
$name
,
$symlink
,
$patchname
,
$desc
) =
@_
;
make_path(
"$tmpdir/$name-tree"
);
make_path(
"$tmpdir/$name-out"
);
symlink
"../$name-out"
,
"$tmpdir/$name-tree/$symlink"
;
my
$patch
= Dpkg::Source::Patch->new(
filename
=>
"$datadir/$patchname"
);
eval
{
$patch
->apply(
"$tmpdir/$name-tree"
,
verbose
=> 0);
};
ok(
rmdir
"$tmpdir/$name-out"
,
$desc
);
}
test_patch_escape(
'c-style-parsed'
,
"\tmp"
,
'c-style.patch'
,
'patch(1) prevents escape using known c-style encoded filename'
);
test_patch_escape(
'c-style-unknown'
,
'\\tmp'
,
'c-style.patch'
,
'patch(1) prevents escape using unknown c-style encoded filename'
);
test_patch_escape(
'index-alone'
,
'symlink'
,
'index-alone.patch'
,
'patch(1) prevents escape using Index: w/o ---/+++ header'
);
test_patch_escape(
'index-+++'
,
'symlink'
,
'index-+++.patch'
,
'patch(1) prevents escape using Index: w/ only +++ header'
);
test_patch_escape(
'index-inert'
,
'symlink'
,
'index-inert.patch'
,
'patch(1) should not fail to apply using an inert Index:'
);
ok(-e
"$tmpdir/index-inert-tree/inert-file"
,
'patch(1) applies correctly with inert Index:'
);
test_patch_escape(
'partial'
,
'symlink'
,
'partial.patch'
,
'patch(1) prevents escape using partial +++ header'
);
test_patch_escape(
'ghost-hunk'
,
'symlink'
,
'ghost-hunk.patch'
,
'patch(1) prevents escape using a disabling hunk'
);
test_patch_escape(
'indent-header'
,
'symlink'
,
'indent-header.patch'
,
'patch(1) prevents escape using indented hunks'
);