Bladeren bron

flatten upload file path inside zip

Keita Sugama 10 jaren geleden
bovenliggende
commit
03b5aa11b9
2 gewijzigde bestanden met toevoegingen van 4 en 8 verwijderingen
  1. 3 8
      lib/Selenium/Remote/Driver.pm
  2. 1 0
      t/01-driver.t

+ 3 - 8
lib/Selenium/Remote/Driver.pm

@@ -21,9 +21,8 @@ use Selenium::Remote::RemoteConnection;
 use Selenium::Remote::Commands;
 use Selenium::Remote::WebElement;
 use File::Spec::Functions ();
-use File::Basename ();
+use File::Basename qw(basename);
 use Sub::Install ();
-use Cwd ();
 use MIME::Base64 ();
 
 use constant FINDERS => {
@@ -2483,7 +2482,7 @@ sub upload_file {
     #WORKAROUND: Since this is undocumented selenium functionality,
     #work around a bug.
     my ($drive, $path, $file) = File::Spec::Functions::splitpath($ret);
-    if ($file ne $filename) {
+    if (defined $raw_content && $file ne $filename) {
         $ret = File::Spec::Functions::catpath($drive,$path,$filename);
     }
 
@@ -2493,13 +2492,9 @@ sub upload_file {
 sub _prepare_file {
     my ($self,$filename) = @_;
 
-    #Apparently zip chokes on non-canonical paths, creating double
-    #submissions sometimes
-    $filename = Cwd::abs_path($filename);
-
     if ( not -r $filename ) { die "upload_file: no such file: $filename"; }
     my $string = "";    # buffer
-    zip $filename => \$string
+    zip $filename => \$string, Name => basename($filename)
       or die "zip failed: $ZipError\n";    # compress the file into string
 
     return {

+ 1 - 0
t/01-driver.t

@@ -525,6 +525,7 @@ UPLOAD: {
     #In the case this is not mocked, it tests a real issue (.. in paths), if not, it makes sure the zip/base64 bits at least don't make us explode.
     like( $fake_driver->upload_file('t/uploadTest'),qr/uploadTest$/,'upload_file: zip/base64 branch' );
     like( $fake_driver->upload_file('t/../t/uploadTest'),qr/uploadTest$/,'upload_file: zip/base64 branch with .. in path' );
+    unlike( $fake_driver->upload_file('t/../t/uploadTest'),qr/\.\./,'upload_file: zip/base64 branch with .. in path' );
 
     #Negative tests to verify that our expected behavior codepath is travelled by tests
     like( exception { $driver->upload_file('@@@SomeFileThatDoesNotExist@@@')},qr/no such file/i,"Passing missing file terminates program");