plots: special chars handling for vega plots paths

Fixes: #6894
This commit is contained in:
Paweł Redzyński
2021-11-17 01:57:35 +02:00
committed by Ruslan Kuprieiev
parent f99d3cda57
commit e0fd0790fc
2 changed files with 19 additions and 1 deletions
+10 -1
View File
@@ -45,8 +45,17 @@ class Renderer(abc.ABC):
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
View File
@@ -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
)