Skip to content

Commit 696bc70

Browse files
Adrian Collistercopybara-github
authored andcommitted
Normalize asset paths before looking them up in the asset dict.
PiperOrigin-RevId: 809702931 Change-Id: Iffccdd8d87b818b87797bd3570888a0e8e423815
1 parent 3831fa5 commit 696bc70

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

dm_control/mjcf/attribute.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ def _get_asset_from_path(self, path):
536536
base_path = self._parent.namescope.get(
537537
constants.BASEPATH, constants.ASSETDIR_NAMESPACE
538538
)
539-
full_path = os.path.join(base_path, path) if base_path else path
539+
full_path = (
540+
os.path.normpath(os.path.join(base_path, path)) if base_path else path
541+
)
540542

541543
# Look in the dict of pre-loaded assets before checking the filesystem.
542544
if path in self._parent.namescope.assets:

dm_control/mjcf/attribute_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ def testFileFromAssetsDict(self):
456456
def testFileFromAssetsDictWithBasepath(self):
457457
prefix = 'fake_filename'
458458
extension = '.whatever'
459-
path = 'invalid/path/' + prefix + extension
459+
path = 'invalid/../path/' + prefix + extension
460460
contents = 'Fake contents'
461-
assets = {os.path.join(ASSETS_DIR, path): contents}
461+
assets = {os.path.normpath(os.path.join(ASSETS_DIR, path)): contents}
462462
mujoco = element.RootElement(assets=assets)
463463
mujoco.files.text_path = ASSETS_DIR
464464
text_file = mujoco.files.add('text', file=path)

0 commit comments

Comments
 (0)