mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
committed by
Ruslan Kuprieiev
parent
f99d3cda57
commit
e0fd0790fc
+10
-1
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
Reference in New Issue
Block a user