From 58c9c7fa67ea728fd79e6c6165687d089ab40cb4 Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander@mail-schlemmer.de>
Date: Mon, 21 Aug 2023 16:38:39 +0200
Subject: [PATCH] FIX: Better implementation of split_restricted_path that
 fixes an error. Also added some documentation.

---
 src/caoscrawler/crawl.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/caoscrawler/crawl.py b/src/caoscrawler/crawl.py
index 70bdb495..6d26553b 100644
--- a/src/caoscrawler/crawl.py
+++ b/src/caoscrawler/crawl.py
@@ -1402,12 +1402,18 @@ def parse_args():
 
 
 def split_restricted_path(path):
-    elements = []
-    while path != "/":
-        path, el = os.path.split(path)
-        if el != "":
-            elements.insert(0, el)
-    return elements
+    """
+    Split a path string into components separated by slashes or other os.path.sep.
+    Empty elements will be removed.
+    """
+    # This implementation leads to infinite loops
+    # for "ill-posed" paths (see test_utilities.py"):
+    # elements = []
+    # while path != "/":
+    #     path, el = os.path.split(path)
+    #     if el != "":
+    #         elements.insert(0, el)
+    return [i for i in path.split(os.path.sep) if i != ""]
 
 
 def main():
-- 
GitLab