Skip to content

Commit eb21c13

Browse files
authored
Andrew/sanitize title (#340)
* Escape user-supplied strings regex * Update CHANGELOG * Sanitize glob as well * Further sanitize title-filename * Improve changelog * More strictly enforce default fig name
1 parent fd7da80 commit eb21c13

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/py/CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
v1.0.0rc15
22
- BUG: Add regex sanitization for auto-filename generation
3+
- Further santiize title to filename conversion
34

45
v1.0.0rc14
56
- Pass `plotlyjs` option through from Kaleido() to PageGenerator()

src/py/kaleido/_fig_tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ def build_fig_spec(fig, path, opts): # noqa: C901
142142
)
143143
if not full_path:
144144
_logger.debug("Looking for title")
145-
prefix = (
146-
fig.get("layout", {}).get("title", {}).get("text", "fig").replace(" ", "_")
147-
)
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"
148149
_logger.debug(f"Found: {prefix}")
149150
name = _next_filename(directory, prefix, ext)
150151
full_path = directory / name

0 commit comments

Comments
 (0)