Skip to content

Commit 781a862

Browse files
committed
Remove trailing slash from URL in Zip extraction
If the URL ends with a trailing slash, the code that searches for the expected ZIP subdirectory calculates it incorrectly, so simply strip any trailing slash if it's present.
1 parent 14b6739 commit 781a862

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

AddonManagerTest/app/test_installer.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,28 @@ def test_code_in_branch_subdirectory_more_than_one(self):
166166

167167
def test_move_code_out_of_subdirectory(self):
168168
"""All files are moved out and the subdirectory is deleted"""
169-
self.mock_addon.url = "https://something.com/something_else/something"
170-
installer = AddonInstaller(self.mock_addon, [])
171-
with tempfile.TemporaryDirectory() as temp_dir:
172-
subdir = os.path.join(temp_dir, f"something-{self.mock_addon.branch}")
173-
os.mkdir(subdir)
174-
with open(os.path.join(subdir, "README.txt"), "w", encoding="utf-8") as f:
175-
f.write("# Test file for unit testing")
176-
with open(os.path.join(subdir, "AnotherFile.txt"), "w", encoding="utf-8") as f:
177-
f.write("# Test file for unit testing")
178-
installer._move_code_out_of_subdirectory(temp_dir)
179-
self.assertTrue(os.path.isfile(os.path.join(temp_dir, "README.txt")))
180-
self.assertTrue(os.path.isfile(os.path.join(temp_dir, "AnotherFile.txt")))
181-
self.assertFalse(os.path.isdir(subdir))
169+
test_urls = [
170+
"https://something.com/something_else/something",
171+
"https://something.com/something_else/something.git",
172+
"https://something.com/something_else/something/",
173+
"https://something.com/something_else/something.git/",
174+
]
175+
for url in test_urls:
176+
with self.subTest(url=url):
177+
self.mock_addon.url = url
178+
installer = AddonInstaller(self.mock_addon, [])
179+
# TODO: Someday use a mock filesystem instead of a temp dir
180+
with tempfile.TemporaryDirectory() as temp_dir:
181+
subdir = os.path.join(temp_dir, f"something-{self.mock_addon.branch}")
182+
os.mkdir(subdir)
183+
with open(os.path.join(subdir, "README.txt"), "w", encoding="utf-8") as f:
184+
f.write("# Test file for unit testing")
185+
with open(os.path.join(subdir, "AnotherFile.txt"), "w", encoding="utf-8") as f:
186+
f.write("# Test file for unit testing")
187+
installer._move_code_out_of_subdirectory(temp_dir)
188+
self.assertTrue(os.path.isfile(os.path.join(temp_dir, "README.txt")))
189+
self.assertTrue(os.path.isfile(os.path.join(temp_dir, "AnotherFile.txt")))
190+
self.assertFalse(os.path.isdir(subdir))
182191

183192
def test_install_by_git(self):
184193
"""Test using git to install. Depends on there being a local git

addonmanager_installer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ def _code_in_branch_subdirectory(self, destination: str) -> bool:
419419

420420
def _expected_subdirectory_name(self) -> str:
421421
url = self.addon_to_install.url
422+
if url.endswith("/"):
423+
url = url[:-1]
422424
if url.endswith(".git"):
423425
url = url[:-4]
424426
_, _, name = url.rpartition("/")

0 commit comments

Comments
 (0)