Skip to content

Commit

Permalink
render: image_converter: Support slash in revision.
Browse files Browse the repository at this point in the history
Fixes #7934
  • Loading branch information
daavoo authored and pared committed Jun 27, 2022
1 parent d448eb5 commit c336507
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dvc/render/image_converter.py
Expand Up @@ -20,7 +20,8 @@ def _write_image(
image_data: bytes,
) -> "StrPath":
img_path = os.path.join(
path, f"{revision}_{filename.replace(os.sep, '_')}"
path,
f"{revision}_{filename}".replace(os.sep, "_").replace("/", "_"),
)
with open(img_path, "wb") as fd:
fd.write(image_data)
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/render/test_image_converter.py
Expand Up @@ -28,3 +28,19 @@ def test_image_converter_with_out(tmp_dir):
}

assert (tmp_dir / "foo" / "r_image.png").read_bytes() == b"content"


def test_image_converter_with_slash_in_revision(tmp_dir):
"""Regression test for #7934"""
data = b"content"
converter = ImageConverter({"out": tmp_dir / "foo"})

datapoints, _ = converter.convert(data, "feature/r", "image.png")

assert datapoints[0] == {
REVISION_FIELD: "feature/r",
"filename": "image.png",
SRC_FIELD: str(tmp_dir / "foo" / "feature_r_image.png"),
}

assert (tmp_dir / "foo" / "feature_r_image.png").read_bytes() == b"content"

0 comments on commit c336507

Please sign in to comment.