From 6182e65756c76ee0058fe7d42276f6eee8741664 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Thu, 13 Feb 2025 16:53:00 +0000 Subject: [PATCH] feat: simplify path construction logic Simplies logic to just use nearest parent as the base instead of traversing downwards. This reduces some redundancy, however fixes a bug with repeated components in the constructed path and also improves performance by skipping a loop altogether. Also fixes recursive extraction tests failing `pandoc_soft_links.zip`. --- lib/init.luau | 15 ++++++++++----- tests/extract.luau | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/init.luau b/lib/init.luau index db83802..5b1908e 100644 --- a/lib/init.luau +++ b/lib/init.luau @@ -163,14 +163,19 @@ function ZipEntry.isSymlink(self: ZipEntry): boolean end function ZipEntry.getPath(self: ZipEntry): string - local path = self.name - local current = self.parent + if self.name == "/" then + return "/" + end + + -- Get just the entry name without the path + local name = string.match(self.name, "([^/]+)/?$") or self.name - while current and current.name ~= "/" do - path = current.name .. path - current = current.parent + if not self.parent or self.parent.name == "/" then + return self.name end + -- Combine parent path with entry name + local path = string.gsub(self.parent:getPath() .. name, "//+", "/") return path end diff --git a/tests/extract.luau b/tests/extract.luau index 8d6ff82..9abd748 100644 --- a/tests/extract.luau +++ b/tests/extract.luau @@ -15,7 +15,6 @@ local FALLIBLES = { "invalid_offset2.zip", "chinese.zip", -- Contains non local specific encoding which can't be parsed without OS APIs "non_utf8.zip", -- FIXME: Lune breaks for non utf8 data in process stdout - "pandoc_soft_links.zip", -- Soft links are tested separately in edge_cases } return function(test: typeof(frktest.test))