diff --git a/blender_asset_tracer/bpathlib.py b/blender_asset_tracer/bpathlib.py index de1abd7..4bd0c22 100644 --- a/blender_asset_tracer/bpathlib.py +++ b/blender_asset_tracer/bpathlib.py @@ -79,13 +79,13 @@ class BlendPath(bytes): sub = BlendPath(subpath) if sub.is_absolute(): raise ValueError("'a / b' only works when 'b' is a relative path") - return BlendPath(os.path.join(self, sub)) + return BlendPath(self.rstrip(b'/') + b'/' + sub) def __rtruediv__(self, parentpath: bytes): """Slash notation like pathlib.Path.""" if self.is_absolute(): raise ValueError("'a / b' only works when 'b' is a relative path") - return BlendPath(os.path.join(parentpath, self)) + return BlendPath(parentpath.rstrip(b'/') + b'/' + self) def to_path(self) -> pathlib.PurePath: """Convert this path to a pathlib.PurePath. diff --git a/tests/test_bpathlib.py b/tests/test_bpathlib.py index 43bfe99..154bbfd 100644 --- a/tests/test_bpathlib.py +++ b/tests/test_bpathlib.py @@ -45,6 +45,11 @@ class BlendPathTest(unittest.TestCase): with self.assertRaises(ValueError): b'/root/and' / BlendPath(b'/parent.blend') + # On Windows+Python 3.5.4 this resulted in b'//root//parent.blend', + # but only if the root is a single term (so not b'//root/and/'). + self.assertEqual(BlendPath(b'//root/parent.blend'), + BlendPath(b'//root/') / b'parent.blend') + def test_mkrelative(self): self.assertEqual(b'//asset.png', BlendPath.mkrelative( Path('/path/to/asset.png'),