Skip to content

Commit be777fe

Browse files
authored
Fix bug w/ url_utils.filepath_from_url + rel paths with a single "/" (#1862)
* Fix bug w/ url_utils.filepath_from_url + rel paths * Relative paths with one "/" and not two "/" were triggering a traceback - ie "./blah" but not "./blah/blah". * remove whitespace --------- Co-authored-by: ssteinbach <[email protected]>
1 parent d6fff83 commit be777fe

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/py-opentimelineio/opentimelineio/url_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def filepath_from_url(urlstr):
7777
filepath = pathlib.PurePosixPath(filepath.drive, *filepath.parts[1:])
7878

7979
# If the specified index is a windows drive, then offset the path
80-
elif pathlib.PureWindowsPath(filepath.parts[1]).drive:
80+
elif (
81+
# relative paths may not have a parts[1]
82+
len(filepath.parts) > 1
83+
and pathlib.PureWindowsPath(filepath.parts[1]).drive
84+
):
8185
# Remove leading "/" if/when `request.url2pathname` yields
8286
# "/S:/path/file.ext"
8387
filepath = pathlib.PurePosixPath(*filepath.parts[1:])

tests/test_url_conversions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def test_posix_urls(self):
7979
processed_url = otio.url_utils.filepath_from_url(url)
8080
self.assertEqual(processed_url, POSIX_PATH)
8181

82+
def test_relative_url(self):
83+
# see github issue #1817 - when a relative URL has only one name after
84+
# the "." (ie ./blah but not ./blah/blah)
85+
self.assertEqual(
86+
otio.url_utils.filepath_from_url(os.path.join(".", "docs")),
87+
"docs",
88+
)
89+
8290

8391
if __name__ == "__main__":
8492
unittest.main()

0 commit comments

Comments
 (0)