Skip to content

Commit 61cbd99

Browse files
authored
Merge branch 'plotly:master' into reno
2 parents a797b16 + eb21c13 commit 61cbd99

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/py/CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.0.0rc15
2+
- BUG: Add regex sanitization for auto-filename generation
3+
- Further santiize title to filename conversion
4+
15
v1.0.0rc14
26
- Pass `plotlyjs` option through from Kaleido() to PageGenerator()
37

src/py/kaleido/_fig_tools.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
import re
23
from pathlib import Path
34

@@ -91,10 +92,14 @@ def to_spec(figure, layout_opts):
9192

9293
def _next_filename(path, prefix, ext):
9394
default = 1 if (path / f"{prefix}.{ext}").exists() else 0
94-
re_number = re.compile(r"^" + prefix + r"-(\d+)\." + ext + r"$")
95+
re_number = re.compile(
96+
r"^" + re.escape(prefix) + r"\-(\d+)\." + re.escape(ext) + r"$",
97+
)
98+
escaped_prefix = glob.escape(prefix)
99+
escaped_ext = glob.escape(ext)
95100
numbers = [
96101
int(match.group(1))
97-
for name in path.glob(f"{prefix}-*.{ext}")
102+
for name in path.glob(f"{escaped_prefix}-*.{escaped_ext}")
98103
if (match := re_number.match(Path(name).name))
99104
]
100105
n = max(numbers, default=default) + 1
@@ -137,9 +142,10 @@ def build_fig_spec(fig, path, opts): # noqa: C901
137142
)
138143
if not full_path:
139144
_logger.debug("Looking for title")
140-
prefix = (
141-
fig.get("layout", {}).get("title", {}).get("text", "fig").replace(" ", "_")
142-
)
145+
prefix = fig.get("layout", {}).get("title", {}).get("text", "fig")
146+
prefix = re.sub(r"[ \-]", "_", prefix)
147+
prefix = re.sub(r"[^a-zA-Z0-9_]", "", prefix)
148+
prefix = prefix or "fig"
143149
_logger.debug(f"Found: {prefix}")
144150
name = _next_filename(directory, prefix, ext)
145151
full_path = directory / name

0 commit comments

Comments
 (0)