summaryrefslogtreecommitdiff
path: root/t/14_leading_separator.t
diff options
context:
space:
mode:
Diffstat (limited to 't/14_leading_separator.t')
-rw-r--r--t/14_leading_separator.t48
1 files changed, 48 insertions, 0 deletions
diff --git a/t/14_leading_separator.t b/t/14_leading_separator.t
new file mode 100644
index 0000000..209b4db
--- /dev/null
+++ b/t/14_leading_separator.t
@@ -0,0 +1,48 @@
+#!perl
+
+# Test the bug-fix for the following bug:
+# Buggy behaviour:
+# Adding file or directory by absolute path results in leading separator
+# being stored in member name.
+# Expected behaviour:
+# Discard leading separator
+# Bug report: http://tech.groups.yahoo.com/group/perl-beginner/message/27085
+
+use strict;
+
+BEGIN {
+ $^W = 1;
+}
+
+use Test::More tests => 1;
+use Archive::Zip;
+
+use Cwd ();
+use File::Spec ();
+
+use t::common;
+
+my $file_relative_path = File::Spec->catfile(TESTDIR, 'file.txt');
+open FH, ">$file_relative_path";
+close FH;
+my $file_absolute_path = File::Spec->rel2abs($file_relative_path);
+
+my $az = Archive::Zip->new();
+$az->addFile($file_absolute_path);
+
+if ($^O eq 'MSWin32') {
+
+ # remove volume from absolute file path
+ my (undef, $directory_path, $current_directory) =
+ File::Spec->splitpath(Cwd::getcwd(), $file_relative_path);
+ $file_absolute_path =
+ File::Spec->catfile($directory_path, $current_directory,
+ $file_relative_path);
+
+ $file_absolute_path =~ s{\\}{/}g; # convert to Unix separators
+}
+
+# expect path without leading separator
+(my $expected_member_name = $file_absolute_path) =~ s{^/}{};
+my ($member_name) = $az->memberNames();
+is($member_name, $expected_member_name, 'no leading separator');