From c83a7f0cd93f549025d6fd43b8bf645bdb6998ff Mon Sep 17 00:00:00 2001 From: coder6583 Date: Sat, 13 Apr 2024 14:08:02 -0400 Subject: [PATCH 1/2] Changed method to remove './' --- lib/archive.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/archive.rb b/lib/archive.rb index 5ea408f6f..7aa7ad105 100644 --- a/lib/archive.rb +++ b/lib/archive.rb @@ -45,7 +45,7 @@ def self.recoverHierarchy(files, root) end subFiles = [] filesNestedSomewhere = files.select{|entry| entry[:pathname].start_with?(root[:pathname]) && !(entry[:pathname] == root[:pathname])} - for file in filesNestedSomewhere + filesNestedSomewhere.each do |file| fileDepth = file[:pathname].chomp("/").count "/" if(fileDepth == depth+1) subFiles << recoverHierarchy(filesNestedSomewhere, file) @@ -67,11 +67,12 @@ def self.sanitize_directories(files) starting_header = -1 # add pre-existing directories to the set - for file in files + files.each do |file| # edge case for removing "./" from pathnames + # file[:pathname] = file[:pathname].gsub(/\.\.\//) {'..-'} if file[:pathname].include?("./") - file[:pathname] = file[:pathname].split("./")[1] + file[:pathname] = file[:pathname].split("./").last end if(file[:directory]) @@ -79,13 +80,13 @@ def self.sanitize_directories(files) end end - for file in files + files.each do |file| # for each file, check if each of its directories and subdir # exist. If it does not, create and add them if(!file[:directory]) paths = file[:pathname].split("/") mac_bs_file = false - for path in paths do + paths.each do |path| # note that __MACOSX is actually a folder # need to check whether the path includes that # for the completeness of cleaned_files @@ -96,7 +97,7 @@ def self.sanitize_directories(files) break end end - for i in 1..(paths.size - 1) do + (1..(paths.size - 1)).each do |i| new_path = paths[0,paths.size-i].join("/") + "/" if(!file_path_set.include?(new_path)) cleaned_files.append({ From 3a2aa67df93cbacb2677f89e578b591e8186819f Mon Sep 17 00:00:00 2001 From: coder6583 Date: Mon, 22 Apr 2024 16:42:07 -0400 Subject: [PATCH 2/2] changed .. to __PARENT__ --- lib/archive.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/archive.rb b/lib/archive.rb index 7aa7ad105..675c207ff 100644 --- a/lib/archive.rb +++ b/lib/archive.rb @@ -70,9 +70,8 @@ def self.sanitize_directories(files) files.each do |file| # edge case for removing "./" from pathnames - # file[:pathname] = file[:pathname].gsub(/\.\.\//) {'..-'} if file[:pathname].include?("./") - file[:pathname] = file[:pathname].split("./").last + file[:pathname] = File.cleanpath(file[:pathname], rel_root = true).gsub("..", "__PARENT__") end if(file[:directory])