Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dvc/render/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ def SCRIPTS(self):
def as_json(self):
raise NotImplementedError

@staticmethod
def _remove_special_chars(string: str):
return string.translate(
{ord(c): "_" for c in r"!@#$%^&*()[]{};,<>?\/:.|`~=_+"}
)

def generate_html(self, path: "StrPath"):
"""this method might edit content of path"""
partial = self._convert(path)
div_id = f"plot_{self.filename.replace('.', '_').replace('/', '_')}"

div_id = self._remove_special_chars(self.filename)
div_id = f"plot_{div_id}"

return self.DIV.format(id=div_id, partial=partial)
9 changes: 9 additions & 0 deletions tests/unit/render/test_renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dvc.render.base import Renderer


def test_remove_special_characters():
special_chars = r"!@#$%^&*()[]{};,<>?\/:.|`~=_+"
dirty = f"plot_name{special_chars}"
assert Renderer._remove_special_chars(dirty) == "plot_name" + "_" * len(
special_chars
)