From ae27abcb006b89f399f459571a0a930f07ea61f6 Mon Sep 17 00:00:00 2001 From: Jose Kahan Date: Thu, 14 Mar 2024 19:00:39 +0100 Subject: [PATCH 1/2] install_addon() didn't take into account dir paths with trailing slashes If install_addon() was called with a path argument pointing to to an extension directory and the path argument value itself ended with a trailing slash, install_addon() would eat the first character of each file it would be adding to the synthetized xpi file. Fixes #13685 --- py/selenium/webdriver/firefox/webdriver.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 574f2ee77db6c..d05d943526f0d 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -125,7 +125,10 @@ def install_addon(self, path, temporary=False) -> str: if os.path.isdir(path): fp = BytesIO() - path_root = len(path) + 1 # account for trailing slash + # filter all trailing slash found in path + path = path.rstrip(os.sep) + # account for trailing slash that will be added by os.walk() + path_root = len(path) + 1 with zipfile.ZipFile(fp, "w", zipfile.ZIP_DEFLATED) as zipped: for base, _, files in os.walk(path): for fyle in files: From 7ebef214a21d30e11f390550c438ba4414943892 Mon Sep 17 00:00:00 2001 From: Jose Kahan Date: Thu, 14 Mar 2024 19:33:58 +0100 Subject: [PATCH 2/2] replacing os.rpath with os.path.normpath() suggested by codiumai-pr-agent-pro --- py/selenium/webdriver/firefox/webdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index d05d943526f0d..75b387c865fc8 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -126,7 +126,7 @@ def install_addon(self, path, temporary=False) -> str: if os.path.isdir(path): fp = BytesIO() # filter all trailing slash found in path - path = path.rstrip(os.sep) + path = os.path.normpath(path) # account for trailing slash that will be added by os.walk() path_root = len(path) + 1 with zipfile.ZipFile(fp, "w", zipfile.ZIP_DEFLATED) as zipped: