Skip to content

Commit 5e191d8

Browse files
authored
Merge pull request #96 from jmjava/cursor/manim-unsafe-unicode-2ccd
Fail closed when manim.unsafe_unicode is not a YAML list
2 parents 000e13b + c051fea commit 5e191d8

5 files changed

Lines changed: 55 additions & 14 deletions

File tree

‎milestones/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ repositories that install `docgen` and maintain their own demo bundle. The
55
library no longer ships an in-repo dogfood; consumers are the integration test
66
of record.
77

8-
**Active:** **[validation-list-keys.md](validation-list-keys.md)** —
9-
`validation.ocr.error_patterns`, `av_sync.visual_types`, and narration-lint
10-
deny pattern lists must be YAML lists, not scalars.
8+
**Active:** **[manim-unsafe-unicode.md](manim-unsafe-unicode.md)** —
9+
`manim.unsafe_unicode` must be a YAML list at config load, not a scalar.
1110

1211
**Shipped:**
12+
- **[validation-list-keys.md](validation-list-keys.md)** —
13+
`validation.ocr.error_patterns`, `av_sync.visual_types`, and narration-lint
14+
deny pattern lists must be YAML lists (#95).
1315
- **[wizard-exclude-lists.md](wizard-exclude-lists.md)** —
1416
`wizard.exclude_patterns` / `scan_extensions` must be string lists (#94).
1517
- **[timestamps-merge-stems.md](timestamps-merge-stems.md)** — CLI `timestamps`

‎milestones/manim-unsafe-unicode.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Milestone: `manim.unsafe_unicode` must be a list at config load
2+
3+
**Status:** Active
4+
**PR:** pending
5+
**Depends on:** `milestones/validation-list-keys.md` (PR #95),
6+
`milestones/config-mapping-keys.md` (PR #83)
7+
8+
## Problem
9+
10+
`manim.unsafe_unicode` as a YAML string already raised `ConfigError` when the
11+
property was **read** (validate / scene-spec-generate). `Config.from_yaml` did
12+
not touch it, so `yaml-generate`, `tts`, and other commands could load a bad
13+
file. A string would also have been iterated as characters inside unicode lint
14+
if anything called the property after a bypass.
15+
16+
## Goal
17+
18+
Evaluate `manim_unsafe_unicode` during `Config.from_yaml` (same as
19+
`manim.scenes`). Use `string_list_block` so items must be YAML strings.
20+
21+
## Done when
22+
23+
- [x] `manim.unsafe_unicode` if present must be a YAML list of strings.
24+
- [x] Missing / null still uses the built-in Pango fallback character list.
25+
- [x] Empty list still disables the unicode lint (`[]`).
26+
- [x] Test for a string value at `Config.from_yaml`.
27+
- [x] `ruff check src/ tests/`
28+
- [x] `pytest tests/`
29+
- [x] `docgen benchmark` (no clock change)
30+
31+
## Out of scope
32+
33+
- The default character list itself is unchanged.

‎milestones/validation-list-keys.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Milestone: validation list keys must not be scalars
22

3-
**Status:** Active
4-
**PR:** pending
3+
**Status:** Shipped
4+
**PR:** #95
55
**Depends on:** `milestones/wizard-exclude-lists.md` (PR #94),
66
`milestones/config-mapping-keys.md` (PR #83)
77

‎src/docgen/config.py‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def __post_init__(self) -> None:
206206
# List-valued keys: a string must not be iterated as characters.
207207
_ = self.segments_all
208208
_ = self.manim_scenes
209+
_ = self.manim_unsafe_unicode
209210
concat = self._block("concat")
210211
src = self._source_label()
211212
for name, segs in concat.items():
@@ -538,15 +539,13 @@ def manim_unsafe_unicode(self) -> list[str]:
538539
"\u2260", "\u2264", "\u2265", "\u2014", "\u2013",
539540
"\u2018", "\u2019", "\u201c", "\u201d", "\u2022",
540541
"\u2026"]
541-
val = self._block("manim").get("unsafe_unicode", default)
542-
if val is None:
543-
return list(default)
544-
if not isinstance(val, list):
545-
raise ConfigError(
546-
f"{self._source_label()}: manim.unsafe_unicode must be a YAML list, "
547-
f"not {type(val).__name__}"
548-
)
549-
return [str(x) for x in val]
542+
return string_list_block(
543+
self._block("manim"),
544+
"unsafe_unicode",
545+
fallback=default,
546+
label="manim.unsafe_unicode",
547+
source=self._source_label(),
548+
)
550549

551550
# -- Compose ----------------------------------------------------------------
552551

‎tests/test_config.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,10 @@ def test_from_yaml_string_post_tts_deny_patterns_raises(tmp_path: Path) -> None:
371371
ConfigError, match="validation.narration_lint.post_tts_deny_patterns must be a YAML list"
372372
):
373373
Config.from_yaml(p)
374+
375+
376+
def test_from_yaml_string_manim_unsafe_unicode_raises(tmp_path: Path) -> None:
377+
p = tmp_path / "docgen.yaml"
378+
p.write_text("manim:\n unsafe_unicode: \"\\u2192\"\n", encoding="utf-8")
379+
with pytest.raises(ConfigError, match="manim.unsafe_unicode must be a YAML list"):
380+
Config.from_yaml(p)

0 commit comments

Comments
 (0)