bindery-cli 0.56.0__tar.gz → 0.57.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/AGENTS.md +25 -11
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/PKG-INFO +1 -1
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/patchnotes.md +57 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/pyproject.toml +1 -1
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/roadmap.md +1 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/spec.md +25 -10
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/__init__.py +1 -1
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/cli.py +27 -17
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/epub.py +10 -7
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/transforms.py +62 -24
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_cli.py +64 -7
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_epub.py +58 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_flags_real_core.py +16 -10
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_transforms.py +165 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/uv.lock +1 -1
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/.github/FUNDING.yml +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/.github/workflows/ci.yml +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/.github/workflows/publish.yml +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/.gitignore +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/LICENSE +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/OBSERVE-RESEARCH.md +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/README.md +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/docs/screenshots/library-sweep.png +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/logo.svg +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/plugin/__init__.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/project.done +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/run_tests.sh +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/scripts/FastSweep.java +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/scripts/build_plugin.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/scripts/fast_sweep.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/__main__.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/audit.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/library.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/observe.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/pagination.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/reserialize.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/validate.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/src/bindery/watermark.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_audit.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_comment_hyphens.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_contamination.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_cover_tocdrift.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_flags_wiring.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_help.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_library.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_matcher_hardening.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_observe.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_pagination.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_plugin.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_reserialize.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_space_renames.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_spine_guard.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_validate.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_version.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_watermark.py +0 -0
- {bindery_cli-0.56.0 → bindery_cli-0.57.0}/tests/test_xml_hardening.py +0 -0
|
@@ -64,12 +64,20 @@ Born from the 2026 library audit (see the user memory `calibre-library-epubcheck
|
|
|
64
64
|
verified against 5.3), ambiguous renames refused per entry (`space_rename_map`),
|
|
65
65
|
accepted under `no_worse` because PKG-010 sits on the warning axis the gate
|
|
66
66
|
does not measure. `--fix-unbound-prefix` (v0.51.0, issue #9, the Calibre
|
|
67
|
-
embed scar) binds
|
|
68
|
-
element that uses it
|
|
67
|
+
embed scar; element half v0.57.0, issue #22) binds a prefix the OPF
|
|
68
|
+
never declares in scope inline on the element that uses it: the
|
|
69
|
+
attribute half (`<dc:identifier id="ID1" ns0:scheme="calibre">`
|
|
69
70
|
whose `xmlns:ns0` sits on a sibling, out of XML scope; two RSC-016 fatals
|
|
70
|
-
plus OPF-030)
|
|
71
|
-
|
|
72
|
-
element
|
|
71
|
+
plus OPF-030) and, since v0.57.0, the element half (the Calibre 9.7.0
|
|
72
|
+
writer self-declares `xmlns:dc` on every dc: element but one, so that
|
|
73
|
+
element's own name dies with `FATAL(RSC-016): The prefix "dc" for
|
|
74
|
+
element "dc:date" is not bound`; the scope walk now checks each start
|
|
75
|
+
tag's own name and binds it on the element): URI evidence is the same
|
|
76
|
+
prefix declared elsewhere in the
|
|
77
|
+
document (all declarations must agree) or the use site's own namespace
|
|
78
|
+
for a Dublin Core site under an OPF-namespaced package (the OPF
|
|
79
|
+
namespace for a DC element's attributes, the DC namespace for a literal
|
|
80
|
+
`dc:` element name), anything else refuses the whole
|
|
73
81
|
document; scope-tracked over a comment/CDATA-aware tokenizer, OPF only
|
|
74
82
|
(content docs have the `--strip-bad-attrs` drop); normal `gate`.
|
|
75
83
|
The v0.55.0 two (the 2026-10-25 issue batch): `--declare-missing-items`
|
|
@@ -145,12 +153,18 @@ Born from the 2026 library audit (see the user memory `calibre-library-epubcheck
|
|
|
145
153
|
gain IS visible, so a run with no measurable improvement is a noop and nothing is
|
|
146
154
|
applied) except the two whose gains sit on axes epubcheck does not measure:
|
|
147
155
|
`--fix-cover` and `--encode-url-spaces`, accepted under the same `no_worse` bar with
|
|
148
|
-
the partial rule intact. One masked-axis rule (v0.51.0, issue #9
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
the partial rule intact. One masked-axis rule (v0.51.0, issue #9, for the
|
|
157
|
+
NCX sync; generalized v0.57.0, issue #22, to every fired fix): when the gate
|
|
158
|
+
answers noop on a book that started AND stayed fatal, `process_book`
|
|
159
|
+
reclassifies the verdict to `partial` (a still-fatal package keeps
|
|
160
|
+
epubcheck's per-file halt, so whatever the fix cleared below the halt --
|
|
161
|
+
the dtb:uid comparison, an error axis, a second latent fatal unmasked by the
|
|
162
|
+
fix that cleared the first: `unbound_prefixes_bound:1`, 1f/1e -> 1f/0e,
|
|
163
|
+
fatals read 1 -> 1 -- measures as no gain, and a silent `equal` buries a
|
|
164
|
+
book that still will not open instead of landing it on the manual list);
|
|
165
|
+
application behavior is unchanged, since still-fatal
|
|
166
|
+
books are never applied, and clean books are untouched (no fatals on both
|
|
167
|
+
sides, no reclassification). One structural veto rides above the counts (v0.52.0,
|
|
154
168
|
issue #10): `process_book` probes source and candidate with `epub.spine_dangles`
|
|
155
169
|
(itemref -> manifest item -> archive entry, resolved through the same helper the
|
|
156
170
|
repair's existence checks use) and rejects any candidate whose dangle count rises
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bindery-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.57.0
|
|
4
4
|
Summary: Audit EPUB body text and repair broken EPUBs with deterministic, epubcheck-gated fixes; atomic in-place replacement in a Calibre library.
|
|
5
5
|
Project-URL: Homepage, https://github.com/VirInvictus/bindery-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/VirInvictus/bindery-cli
|
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# bindery-cli Patch Notes
|
|
2
2
|
|
|
3
|
+
## v0.57.0 (2026-10-25)
|
|
4
|
+
|
|
5
|
+
### Issue #22: the embed scar's element half, and the end of the silent equal
|
|
6
|
+
|
|
7
|
+
The reconcile-embed fallout's last scar shape, plus the reporting gap its
|
|
8
|
+
investigation exposed.
|
|
9
|
+
|
|
10
|
+
**`--fix-unbound-prefix` binds element prefixes (shape 1).** Calibre
|
|
11
|
+
9.7.0's `embed_metadata` self-declares `xmlns:dc` on every dc: element it
|
|
12
|
+
writes but one, leaving that element's own ELEMENT prefix unbound:
|
|
13
|
+
`FATAL(RSC-016): The prefix "dc" for element "dc:date" is not bound`. The
|
|
14
|
+
v0.51.0 repair covered attribute prefixes only (`ns0:scheme`); the element
|
|
15
|
+
name is a different use site and nothing in the inventory touched it, so
|
|
16
|
+
the specimen chain sat one fatal apart from clean with no repair left to
|
|
17
|
+
run. The same scope-tracking walk now checks each start tag's own name:
|
|
18
|
+
an unbound element prefix is bound inline on the element, the exact shape
|
|
19
|
+
the file's healthy siblings already use. The evidence rules carry over
|
|
20
|
+
with one addition: rule 1 is unchanged (the prefix declared elsewhere in
|
|
21
|
+
the document, every declaration agreeing), and rule 2 for a literal `dc:`
|
|
22
|
+
element under an OPF-namespaced package resolves to the DC namespace
|
|
23
|
+
itself (the attribute half's rule 2 names the OPF namespace because
|
|
24
|
+
`opf:scheme` rides on DC elements; a `dc:` element IS the Dublin Core
|
|
25
|
+
element). Ambiguous or unevidenced prefixes still refuse the whole
|
|
26
|
+
document, clean documents stay byte-identical, and the each-use-site
|
|
27
|
+
counting contract holds (nested unbound elements each get their own
|
|
28
|
+
declaration, mirroring the attribute half). One start tag never carries
|
|
29
|
+
two declarations for one prefix (XML forbids the duplicate attribute;
|
|
30
|
+
the code-review pass caught the collision between an unbound element
|
|
31
|
+
prefix and an unbound same-prefix attribute on one tag, and fixed the
|
|
32
|
+
attribute-vs-attribute variant the attribute half had always carried).
|
|
33
|
+
Live gate on the specimen
|
|
34
|
+
(Hackers, the issue's own chain): the scarred original went
|
|
35
|
+
`1f/1e -> 0f/1e` with `unbound_prefixes_bound:2` (attribute + element in
|
|
36
|
+
one run), and the half-repaired intermediate that v0.56.0 refused as
|
|
37
|
+
`equal` now repairs (`1f/0e -> 0f/1e`, the element bind alone). The
|
|
38
|
+
residual error on the specimen is NCX-001, not embed damage: its 2010-era
|
|
39
|
+
NCX spells every element with the `ncx:` prefix, which the always-on
|
|
40
|
+
dtb:uid sync's `<meta\b` matcher does not read; that sync gap is recorded
|
|
41
|
+
on the issue and left unrepaired here.
|
|
42
|
+
|
|
43
|
+
**Still-fatal noops reclassify as partial (shape 2).** The same
|
|
44
|
+
investigation caught the gate answering `equal (no measurable gain)` on a
|
|
45
|
+
book whose fix had cleared one fatal and unmasked a latent second:
|
|
46
|
+
`unbound_prefixes_bound:1` fired, `1f/1e -> 1f/0e`, fatals read 1 -> 1,
|
|
47
|
+
and the silent skip buried a book that still will not open. The v0.51.0
|
|
48
|
+
masked-ncx-gain rule already reclassified exactly this shape for the uid
|
|
49
|
+
sync; it is now general (the gate's noop on any book that started and
|
|
50
|
+
stayed fatal means the fix's real axis lives below epubcheck's per-file
|
|
51
|
+
halt, whatever the fix was): the verdict is `partial`, the book lands on
|
|
52
|
+
the manual list (`still_fatal`), and the still-fatal rule is untouched
|
|
53
|
+
(partial candidates were never auto-applied). Clean books are unaffected:
|
|
54
|
+
the rule cannot fire without fatals on both sides, and the gate's own
|
|
55
|
+
partial and reject answers never enter it.
|
|
56
|
+
|
|
57
|
+
Twenty-five structural repairs. Suite: 789 tests.
|
|
58
|
+
|
|
59
|
+
|
|
3
60
|
## v0.56.0 (2026-10-25)
|
|
4
61
|
|
|
5
62
|
### The two boxed recipes, built: the OPF-030 wiring and the CSS-007 font half
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bindery-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.57.0"
|
|
8
8
|
description = "Audit EPUB body text and repair broken EPUBs with deterministic, epubcheck-gated fixes; atomic in-place replacement in a Calibre library."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
classifiers = [
|
|
@@ -50,6 +50,7 @@ The plugin vendors the core and never gates (the epubcheck latency ruling).
|
|
|
50
50
|
| 0.54 | The surgery fixes: `fix_ncx_playorder` is contract-gated (epubcheck's playOrder contract: same-target sharing, distinct-target distinctness, contiguous 1..K across navTarget/pageTarget; the old unconditional 1..N renumbering rewrote valid TOCs into violations, 211 of 579 firings gate-rejected vs 17 real fixes) and `_PROTECTED_RE` protects the Calibre `/*<![CDATA[*/ ... /*]]>*/` wrapper as one unit (the bare CDATA span exposed the trailing `*/` to strip_prolog_junk's amputation, 111 phantom-fix rejections); verified by the 2026-10-24 error-code surgery (OBSERVE-RESEARCH.md) | v0.54.0 |
|
|
51
51
|
| 0.55 | The issue-batch release (issues #11-#16, the 2026-10-24 surgery's follow-ups): `--strip-epub3-attrs` extended with `role` + `aria-hidden` (the census killed the DOCTYPE-gate concern: epubcheck is profile-driven; #11), `--fix-duplicate-ids` for content docs (#14), `--declare-missing-items` for RSC-008 (#16, with the prune's RSC-001 boundary documented), the size-scaled epubcheck timeout with one retry and the distinct `OracleTimeout` (#15), observe schema v2 (`codes.messages` rename, true `codes.occurrences`, the `counting` block, v1 `--against` accepted; #13), the #12 content-model ruling (measured, not repaired: the wrap changes layout), and the #17 census lanes (RSC-012/OPF-029 dispositions on existing flags; OPF-030/CSS-007/RSC-004 recorded leave-measured with recipes) | v0.55.0 |
|
|
52
52
|
| 0.56 | The boxed recipes, built same-day on the follow-up call: `--fix-unique-identifier` (the OPF-030 recipe: wire the package's named id onto the first dc:identifier, refuses every ambiguous shape, and predicts the post-wiring uid so the NCX sync the broken wiring was masking fires in the same run -- eagle 2e -> 1e accept) and the CSS-007 font half inside `--fix-media-types` (font/* blessed on both package versions, magic confirmed, .eot never touched; accepted under no_worse because the gain sits on the INFO axis -- Brave New World 8 fonts normalized, CSS-007 cleared) | v0.56.0 |
|
|
53
|
+
| 0.57 | The embed scar's element half and the end of the silent equal (issue #22): `--fix-unbound-prefix` now binds an unbound ELEMENT prefix inline (the 9.7.0 writer self-declares xmlns:dc on every dc: element but one; rule 2 for a literal dc: element resolves to the DC namespace itself; Hackers 1f/1e -> 0f/1e with both binds in one run, and the half-repaired intermediate that read equal now repairs), and the masked-axis reclassification generalizes from the v0.51.0 NCX sync to every fired fix: a gate noop on a book that started and stayed fatal reads partial (the manual list) instead of a silent equal; the ncx:-prefixed dtb:uid sync gap found on the specimen is recorded, not repaired | v0.57.0 |
|
|
53
54
|
|
|
54
55
|
## Open work
|
|
55
56
|
|
|
@@ -358,16 +358,20 @@ leftovers whose failing OPF is a stale non-rootfile are unreachable by construct
|
|
|
358
358
|
quote before the next `<` (a real multi-line value closes quote-first), and only
|
|
359
359
|
double-quoted values are judged. It runs before the other tag-shape readers, which an
|
|
360
360
|
open value otherwise lies to.
|
|
361
|
-
- **`--fix-unbound-prefix`**: bind
|
|
362
|
-
the element that uses it (the Calibre embed scar
|
|
363
|
-
`ns0:scheme` while the `xmlns:ns0` declaration sits on a sibling, out
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
361
|
+
- **`--fix-unbound-prefix`**: bind a prefix the OPF never declares in scope inline on
|
|
362
|
+
the element that uses it (the Calibre embed scar: issue #9's attribute half, one dc:
|
|
363
|
+
element carrying `ns0:scheme` while the `xmlns:ns0` declaration sits on a sibling, out
|
|
364
|
+
of XML scope; and issue #22's element half, a later writer build self-declaring
|
|
365
|
+
`xmlns:dc` on every dc: element but one, so that element's own name dies with the
|
|
366
|
+
RSC-016 "prefix is not bound" fatal). Either scar makes the whole package
|
|
367
|
+
unparseable, which also costs OPF-030 on the unique-identifier and masks the NCX-001
|
|
368
|
+
comparison. The declaration is inserted on the user (element name or attribute
|
|
369
|
+
alike), the shape the file's own healthy siblings already use. The URI is
|
|
370
|
+
evidence-based, never guessed: the same prefix declared elsewhere in the document
|
|
371
|
+
with every declaration agreeing, or the use site's own namespace under an
|
|
372
|
+
OPF-namespaced package (the OPF namespace for a Dublin Core element's attributes,
|
|
373
|
+
the canonical EPUB 2 `opf:scheme` shape; the DC namespace for a literal `dc:` element
|
|
374
|
+
name); anything else refuses the document untouched. Scope is tracked
|
|
371
375
|
with a lenient element stack over a comment/CDATA-aware tokenizer, so declarations
|
|
372
376
|
that genuinely cover a use satisfy it without an edit and clean documents are
|
|
373
377
|
byte-identical. Runs on the OPF only: content documents have the
|
|
@@ -456,6 +460,17 @@ be run or its output cannot be parsed during a validated run, the book is an `er
|
|
|
456
460
|
the gate has not accepted anything, so nothing is applied or written. With
|
|
457
461
|
`--no-validate`, the gate is skipped and repairs are trusted on the RepairReport alone.
|
|
458
462
|
|
|
463
|
+
One reporting rule rides on the noop verdict: the masked-axis reclassification. A
|
|
464
|
+
`noop` on a book that started fatal means the fix fired and the count did not move,
|
|
465
|
+
and with fatals still standing epubcheck's per-file halt hides whatever the fix
|
|
466
|
+
actually cleared below the halt: the dtb:uid comparison (issue #9, where the rule
|
|
467
|
+
was first scoped to the NCX sync), a cleared error axis, or a second latent fatal
|
|
468
|
+
unmasked by the fix that cleared the first (issue #22's embed scar:
|
|
469
|
+
`unbound_prefixes_bound` fired, `1f/1e -> 1f/0e`, fatals read 1 -> 1). Real,
|
|
470
|
+
unmeasurable work on a book that still will not open is `partial`, never a silent
|
|
471
|
+
`equal`: partial lands the book on the manual list. Application behavior is
|
|
472
|
+
unchanged (still-fatal candidates are never auto-applied).
|
|
473
|
+
|
|
459
474
|
One structural veto rides above the count gate: the spine-resolution check. The
|
|
460
475
|
message count is not spine-aware, so a repair that orphans live itemrefs (manifest
|
|
461
476
|
items pruned whose files the archive still carries, idrefs rewritten to forms that
|
|
@@ -11,7 +11,7 @@ Calibre plugin built from this core.
|
|
|
11
11
|
Single source of truth for the version. pyproject.toml must match VERSION below.
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
|
-
VERSION = "0.
|
|
14
|
+
VERSION = "0.57.0"
|
|
15
15
|
__version__ = VERSION
|
|
16
16
|
|
|
17
17
|
from .epub import RepairReport, repair_epub # noqa: E402
|
|
@@ -177,15 +177,21 @@ def process_book(
|
|
|
177
177
|
watermark_refusals=report.watermark_refusals,
|
|
178
178
|
)
|
|
179
179
|
verdict = gate(before, after)
|
|
180
|
-
if verdict == "noop" and
|
|
181
|
-
# The
|
|
182
|
-
#
|
|
183
|
-
#
|
|
184
|
-
#
|
|
185
|
-
#
|
|
186
|
-
#
|
|
187
|
-
#
|
|
188
|
-
#
|
|
180
|
+
if verdict == "noop" and before.fatals > 0:
|
|
181
|
+
# The masked-axis rule. v0.51.0 (issue #9) named it for the NCX uid
|
|
182
|
+
# sync; v0.57.0 (issue #22) generalizes it to every fired fix. A
|
|
183
|
+
# still-fatal package keeps epubcheck's per-file halt, so any gain
|
|
184
|
+
# living below the halt — the dtb:uid comparison, a cleared error
|
|
185
|
+
# axis, a second latent fatal unmasked by the fix that cleared the
|
|
186
|
+
# first (the Hackers dc:date scar: unbound_prefixes_bound fired,
|
|
187
|
+
# 1f/1e -> 1f/0e, fatals read 1 -> 1) — measures as no gain. The
|
|
188
|
+
# honest verdict for real, unmeasurable work on a book that still
|
|
189
|
+
# will not open is partial, never equal: partial lands the book on
|
|
190
|
+
# the manual list (the sweep's still_fatal set) instead of vanishing
|
|
191
|
+
# into a silent skip. Application behavior is unchanged: still-fatal
|
|
192
|
+
# books are never auto-applied, and the gate's own partial/reject
|
|
193
|
+
# answers (fatals reduced, or a regression) never enter this branch
|
|
194
|
+
# (gate noop with fatals before implies fatals after).
|
|
189
195
|
verdict = "partial"
|
|
190
196
|
if (
|
|
191
197
|
report.fixes.get("stripped_pagination")
|
|
@@ -1900,18 +1906,22 @@ _REPAIR_FLAG_TABLE: dict[str, list[tuple[str, str, str]]] = {
|
|
|
1900
1906
|
),
|
|
1901
1907
|
(
|
|
1902
1908
|
"fix_unbound_prefix",
|
|
1903
|
-
"bind an undeclared
|
|
1904
|
-
"bind
|
|
1909
|
+
"bind an undeclared namespace prefix inline (Calibre embed scar)",
|
|
1910
|
+
"bind a prefix the OPF never declares in scope inline on the "
|
|
1905
1911
|
"element that uses it (RSC-016 'prefix is not bound'): calibre's "
|
|
1906
1912
|
"embed_metadata writer can leave one dc: element carrying "
|
|
1907
1913
|
"ns0:scheme while the xmlns declaration sits on a sibling, out of "
|
|
1908
|
-
"XML scope,
|
|
1914
|
+
"XML scope, and a later writer build leaves one dc: element's own "
|
|
1915
|
+
"name unbound the same way (every dc: element self-declares "
|
|
1916
|
+
"xmlns:dc except one, so <dc:date> dies with RSC-016); either "
|
|
1917
|
+
"scar fatals the whole package (plus OPF-030 on the "
|
|
1909
1918
|
"unique-identifier). The URI is evidence-based, never guessed: "
|
|
1910
|
-
"the same prefix declared elsewhere in the document, or the
|
|
1911
|
-
"
|
|
1912
|
-
"
|
|
1913
|
-
"
|
|
1914
|
-
"
|
|
1919
|
+
"the same prefix declared elsewhere in the document, or the use "
|
|
1920
|
+
"site's own namespace under an OPF-namespaced package (the OPF "
|
|
1921
|
+
"namespace for a Dublin Core element's attributes, the DC "
|
|
1922
|
+
"namespace for a dc: element name); anything else refuses the "
|
|
1923
|
+
"document untouched. Content documents are not touched (their "
|
|
1924
|
+
"unbound prefixes have the --strip-bad-attrs drop).",
|
|
1915
1925
|
),
|
|
1916
1926
|
],
|
|
1917
1927
|
"lossy strips (these delete converter-injected content; accepted on a no-worse bar)": [
|
|
@@ -1766,15 +1766,18 @@ def repair_epub(
|
|
|
1766
1766
|
own `>` (`<p class="footnote>` -> `<p class="footnote">`; the RSC-016
|
|
1767
1767
|
'must not contain the < character' fatal). It runs before the tag-shape
|
|
1768
1768
|
readers, which an open value otherwise lies to.
|
|
1769
|
-
With `unbound_prefix`, bind
|
|
1769
|
+
With `unbound_prefix`, bind a prefix the OPF never declares in scope
|
|
1770
1770
|
inline on the element that uses it (the Calibre embed scar: one dc:
|
|
1771
1771
|
element carries `ns0:scheme` while the xmlns declaration sits on a
|
|
1772
|
-
sibling, out of scope;
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1772
|
+
sibling, out of scope; and, issue #22, the writer's own element half —
|
|
1773
|
+
every dc: element self-declares `xmlns:dc` but one, and that
|
|
1774
|
+
`<dc:date>`'s ELEMENT prefix is unbound; two RSC-016 fatals plus OPF-030
|
|
1775
|
+
on the unique-identifier between them). The URI is evidence-based: the
|
|
1776
|
+
same prefix declared elsewhere in the document, or the use site's own
|
|
1777
|
+
namespace under an OPF-namespaced package (the OPF namespace for a
|
|
1778
|
+
Dublin Core element's attributes, the DC namespace for a `dc:` element
|
|
1779
|
+
name); anything else refuses the whole document. Content documents are
|
|
1780
|
+
not touched (their unbound prefixes have the --strip-bad-attrs drop).
|
|
1778
1781
|
With `unique_identifier`, wire the OPF-030 dangling unique-identifier: add
|
|
1779
1782
|
the id the package names to the first dc:identifier start tag when no
|
|
1780
1783
|
element carries it. Refuses to guess (absent/empty attribute, non-NCName
|
|
@@ -1153,18 +1153,23 @@ def fix_unbound_prefixes(opf: str) -> tuple[str, int]:
|
|
|
1153
1153
|
Calibre's embed_metadata writer has been observed to leave one dc: element
|
|
1154
1154
|
carrying an attribute prefix (``ns0:scheme``) whose xmlns declaration never
|
|
1155
1155
|
made it into the document: the declaration sits on a sibling, and XML scope
|
|
1156
|
-
ends at the sibling's end tag.
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1156
|
+
ends at the sibling's end tag. A later writer build (Calibre 9.7.0, issue
|
|
1157
|
+
#22) leaves one dc: element's own ELEMENT prefix unbound the same way: it
|
|
1158
|
+
self-declares ``xmlns:dc`` on every dc: element but one, and that one
|
|
1159
|
+
(``<dc:date>``) dies with RSC-016. Both scars are the same defect — a
|
|
1160
|
+
prefix used where XML scope has no binding for it — and the repair is the
|
|
1161
|
+
shape the file's own healthy siblings already use: declare the prefix on
|
|
1162
|
+
the element that uses it, on its name or its attribute alike.
|
|
1160
1163
|
|
|
1161
1164
|
The URI is evidence-based, never guessed: (1) the same prefix declared
|
|
1162
1165
|
elsewhere in the document, every declaration agreeing on one URI; (2) the
|
|
1163
|
-
prefix declared nowhere, but the
|
|
1164
|
-
element
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1166
|
+
prefix declared nowhere, but the use site is Dublin Core under a package
|
|
1167
|
+
element that declares the OPF namespace — for an attribute, the carrying
|
|
1168
|
+
element is DC (its element prefix resolves to the DC namespace, or the
|
|
1169
|
+
literal ``dc:`` spelling when that is itself unbound) and the canonical
|
|
1170
|
+
EPUB 2 ``opf:scheme``/``opf:role`` shape names the OPF namespace; for an
|
|
1171
|
+
element, the literal ``dc:`` spelling IS the Dublin Core element, and its
|
|
1172
|
+
namespace is the DC one; (3) anything else refuses the whole document (an
|
|
1168
1173
|
invented URI would be a guess, and a half-bound package is still fatal, so
|
|
1169
1174
|
a partial fix would buy nothing). Declarations scoped to an ancestor (or
|
|
1170
1175
|
to the element itself) satisfy the check without an edit, so clean
|
|
@@ -1234,34 +1239,67 @@ def fix_unbound_prefixes(opf: str) -> tuple[str, int]:
|
|
|
1234
1239
|
for u in (default_uri, *decls.values())
|
|
1235
1240
|
if u
|
|
1236
1241
|
)
|
|
1237
|
-
# Push before the
|
|
1238
|
-
#
|
|
1242
|
+
# Push before the checks: the element's own declarations apply to its
|
|
1243
|
+
# own name and its own attributes alike.
|
|
1239
1244
|
scope.append((name, decls))
|
|
1240
|
-
|
|
1245
|
+
# (prefix, fallback) pairs awaiting a URI: every use site whose prefix
|
|
1246
|
+
# is unbound in scope. The fallback is the URI rule 2 names for that
|
|
1247
|
+
# use site, or "" when rule 2 has nothing to say (it needs a Dublin
|
|
1248
|
+
# Core use site under an OPF-namespaced package; anything else would
|
|
1249
|
+
# be a guess and refuses instead).
|
|
1250
|
+
elem_prefix, esep, _ = name.partition(":")
|
|
1251
|
+
elem_ns = None
|
|
1252
|
+
for _, d in reversed(scope):
|
|
1253
|
+
if elem_prefix in d:
|
|
1254
|
+
elem_ns = d[elem_prefix]
|
|
1255
|
+
break
|
|
1256
|
+
wanted: list[tuple[str, str]] = []
|
|
1257
|
+
# One declaration per prefix per start tag (XML forbids a duplicate
|
|
1258
|
+
# attribute): the element's own binding names the prefix for the
|
|
1259
|
+
# whole tag, so an attribute on the same tag never queues it again.
|
|
1260
|
+
pending: set[str] = set()
|
|
1261
|
+
if (
|
|
1262
|
+
esep
|
|
1263
|
+
and elem_prefix not in _PREBOUND_PREFIXES
|
|
1264
|
+
and not any(elem_prefix in d for _, d in scope)
|
|
1265
|
+
):
|
|
1266
|
+
# The element's own name can carry the scar (issue #22): the
|
|
1267
|
+
# embed writer self-declares xmlns:dc on every dc: element but
|
|
1268
|
+
# one, and that element's own prefix is then unbound. A
|
|
1269
|
+
# dc:-prefixed element under an OPF-namespaced package is Dublin
|
|
1270
|
+
# Core by the spec, so its fallback URI is the DC namespace.
|
|
1271
|
+
fallback = _DC_NS if pkg_ns and elem_prefix == "dc" else ""
|
|
1272
|
+
wanted.append((elem_prefix, fallback))
|
|
1273
|
+
pending.add(elem_prefix)
|
|
1241
1274
|
for aname in attr_names:
|
|
1242
1275
|
prefix, sep, _ = aname.partition(":")
|
|
1243
1276
|
if not sep or prefix in _PREBOUND_PREFIXES:
|
|
1244
1277
|
continue
|
|
1245
1278
|
if any(prefix in d for _, d in scope):
|
|
1246
1279
|
continue
|
|
1280
|
+
if prefix in pending:
|
|
1281
|
+
continue
|
|
1282
|
+
# The canonical EPUB 2 attribute shape: opf:scheme/opf:role ride
|
|
1283
|
+
# on Dublin Core elements with the OPF namespace.
|
|
1284
|
+
fallback = (
|
|
1285
|
+
_OPF_NS
|
|
1286
|
+
if pkg_ns
|
|
1287
|
+
and (elem_ns == _DC_NS or (elem_ns is None and elem_prefix == "dc"))
|
|
1288
|
+
else ""
|
|
1289
|
+
)
|
|
1290
|
+
wanted.append((prefix, fallback))
|
|
1291
|
+
pending.add(prefix)
|
|
1292
|
+
binds: list[str] = []
|
|
1293
|
+
for prefix, fallback in wanted:
|
|
1247
1294
|
uris = decl_uris.get(prefix)
|
|
1248
1295
|
if uris is not None:
|
|
1249
1296
|
if len(uris) != 1:
|
|
1250
1297
|
return opf, 0 # one prefix, two URIs: intent unreadable
|
|
1251
1298
|
uri = next(iter(uris))
|
|
1299
|
+
elif fallback:
|
|
1300
|
+
uri = fallback
|
|
1252
1301
|
else:
|
|
1253
|
-
|
|
1254
|
-
elem_ns = None
|
|
1255
|
-
for _, d in reversed(scope):
|
|
1256
|
-
if elem_prefix in d:
|
|
1257
|
-
elem_ns = d[elem_prefix]
|
|
1258
|
-
break
|
|
1259
|
-
if pkg_ns and (
|
|
1260
|
-
elem_ns == _DC_NS or (elem_ns is None and elem_prefix == "dc")
|
|
1261
|
-
):
|
|
1262
|
-
uri = _OPF_NS
|
|
1263
|
-
else:
|
|
1264
|
-
return opf, 0 # no evidence: refuse the whole document
|
|
1302
|
+
return opf, 0 # no evidence: refuse the whole document
|
|
1265
1303
|
binds.append(f' xmlns:{prefix}="{uri}"')
|
|
1266
1304
|
if binds:
|
|
1267
1305
|
# Insert directly after the element name, the position the
|
|
@@ -316,6 +316,30 @@ class TestRepairJson(unittest.TestCase):
|
|
|
316
316
|
self.assertEqual(data["before"]["fatals"], 1)
|
|
317
317
|
self.assertEqual(data["after"]["fatals"], 0)
|
|
318
318
|
|
|
319
|
+
def test_masked_partial_writes_with_dst(self):
|
|
320
|
+
# Issue #22's reclassification at the verb level: a still-fatal
|
|
321
|
+
# gate-noop book reads partial (not equal), and an explicit DST is
|
|
322
|
+
# still written, labeled PARTIAL (rc 0: the file is a real change
|
|
323
|
+
# worth keeping, the label says it is not fixed).
|
|
324
|
+
with tempfile.TemporaryDirectory() as td:
|
|
325
|
+
src = Path(td) / "in.epub"
|
|
326
|
+
dst = Path(td) / "out.epub"
|
|
327
|
+
build(src)
|
|
328
|
+
jout = Path(td) / "repair.json"
|
|
329
|
+
results = [CheckResult(1, 1, 0), CheckResult(1, 1, 0)]
|
|
330
|
+
out = io.StringIO()
|
|
331
|
+
with (
|
|
332
|
+
mock.patch("bindery.cli.run_epubcheck", side_effect=results),
|
|
333
|
+
redirect_stdout(out),
|
|
334
|
+
):
|
|
335
|
+
rc = main(["repair", str(src), str(dst), "--json", str(jout)])
|
|
336
|
+
data = json.loads(jout.read_text())
|
|
337
|
+
self.assertTrue(dst.exists())
|
|
338
|
+
self.assertEqual(rc, 0)
|
|
339
|
+
self.assertEqual(data["status"], "partial")
|
|
340
|
+
self.assertTrue(data["applied"])
|
|
341
|
+
self.assertIn("PARTIAL", out.getvalue())
|
|
342
|
+
|
|
319
343
|
def test_nochange_and_reject_records_are_written(self):
|
|
320
344
|
with tempfile.TemporaryDirectory() as td:
|
|
321
345
|
src2 = Path(td) / "in2.epub"
|
|
@@ -1700,7 +1724,11 @@ class TestSweepWorkers(unittest.TestCase):
|
|
|
1700
1724
|
|
|
1701
1725
|
def oracle(path):
|
|
1702
1726
|
checked.append(path.name)
|
|
1703
|
-
|
|
1727
|
+
# Error-flat, never fatal: a fatal-flat book with a fired core
|
|
1728
|
+
# fix reads partial since the masked-axis rule (issue #22), and
|
|
1729
|
+
# partial books are trouble (exit 2) rather than the rc-0 path
|
|
1730
|
+
# this limit/window mechanic tests.
|
|
1731
|
+
return CheckResult(0, 1, 0)
|
|
1704
1732
|
|
|
1705
1733
|
with tempfile.TemporaryDirectory() as td:
|
|
1706
1734
|
for name in ("a", "b", "c", "d", "e"):
|
|
@@ -1737,7 +1765,8 @@ class TestSweepWorkers(unittest.TestCase):
|
|
|
1737
1765
|
|
|
1738
1766
|
def oracle(path):
|
|
1739
1767
|
checked.append(path.name)
|
|
1740
|
-
|
|
1768
|
+
# Error-flat, never fatal: see test_limit_stays_lazy_within_one_window.
|
|
1769
|
+
return CheckResult(0, 1, 0)
|
|
1741
1770
|
|
|
1742
1771
|
with tempfile.TemporaryDirectory() as td:
|
|
1743
1772
|
for name in ("a", "b", "c", "d", "e"):
|
|
@@ -1882,11 +1911,13 @@ class TestStripStubDocsGate(unittest.TestCase):
|
|
|
1882
1911
|
self.assertEqual(o.status, "reject")
|
|
1883
1912
|
|
|
1884
1913
|
|
|
1885
|
-
class
|
|
1886
|
-
"""
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1914
|
+
class TestMaskedFatalGain(unittest.TestCase):
|
|
1915
|
+
"""The gate's masked axis. Issue #9 named it for the NCX uid sync; issue
|
|
1916
|
+
#22 generalized it to every fired fix: a still-fatal package keeps
|
|
1917
|
+
epubcheck's per-file halt, so real work below the halt — a sync, a
|
|
1918
|
+
cleared error axis, a second latent fatal unmasked by the fix that
|
|
1919
|
+
cleared the first — measures as no gain, and the verdict must not call
|
|
1920
|
+
it gainless. Noop + fatals on both sides reclassifies to partial: real
|
|
1890
1921
|
work the oracle could not see, still-fatal rules intact."""
|
|
1891
1922
|
|
|
1892
1923
|
def _verdict(self, before, after, report):
|
|
@@ -1923,6 +1954,32 @@ class TestMaskedNcxUidGain(unittest.TestCase):
|
|
|
1923
1954
|
o = self._verdict(CheckResult(1, 0, 0), CheckResult(2, 0, 0), report)
|
|
1924
1955
|
self.assertEqual(o.status, "reject")
|
|
1925
1956
|
|
|
1957
|
+
def test_fired_fix_still_fatal_is_partial_not_equal(self):
|
|
1958
|
+
# Issue #22's exact shape (the Hackers dc:date scar): the fix fired,
|
|
1959
|
+
# cleared one fatal, and unmasked a latent second (1f/1e -> 1f/0e):
|
|
1960
|
+
# fatals read 1 -> 1, the gate says noop, and equal would hide a
|
|
1961
|
+
# book that still will not open.
|
|
1962
|
+
report = RepairReport(fixes={"unbound_prefixes_bound": 1})
|
|
1963
|
+
o = self._verdict(CheckResult(1, 1, 0), CheckResult(1, 0, 0), report)
|
|
1964
|
+
self.assertEqual(o.status, "partial")
|
|
1965
|
+
self.assertNotIn("no measurable gain", o.summary)
|
|
1966
|
+
self.assertIn("unbound_prefixes_bound", o.summary)
|
|
1967
|
+
|
|
1968
|
+
def test_unrelated_fix_on_still_fatal_book_is_partial(self):
|
|
1969
|
+
# Any fired fix under a still-fatal package sits on a masked axis:
|
|
1970
|
+
# the per-file halt hides whatever the fix cleared below it.
|
|
1971
|
+
report = RepairReport(fixes={"fix_manifest_ids": 1})
|
|
1972
|
+
o = self._verdict(CheckResult(2, 0, 0), CheckResult(2, 0, 0), report)
|
|
1973
|
+
self.assertEqual(o.status, "partial")
|
|
1974
|
+
|
|
1975
|
+
def test_clean_book_noop_stays_equal(self):
|
|
1976
|
+
# No fatals, no unmasking: a noop is a noop, and a clean book must
|
|
1977
|
+
# not land on the manual list.
|
|
1978
|
+
report = RepairReport(fixes={"fix_manifest_ids": 1})
|
|
1979
|
+
o = self._verdict(CheckResult(0, 1, 0), CheckResult(0, 1, 0), report)
|
|
1980
|
+
self.assertEqual(o.status, "equal")
|
|
1981
|
+
self.assertIn("no measurable gain", o.summary)
|
|
1982
|
+
|
|
1926
1983
|
|
|
1927
1984
|
class TestHelpLayout(unittest.TestCase):
|
|
1928
1985
|
"""The two-level help contract (the 2026-10-06 restructure): the compact
|
|
@@ -2322,6 +2322,28 @@ SCARRED_OPF = (
|
|
|
2322
2322
|
'<spine toc="ncx"><itemref idref="c1"/></spine></package>'
|
|
2323
2323
|
)
|
|
2324
2324
|
|
|
2325
|
+
# The Hackers shape (issue #22): no xmlns:dc on <metadata>; every dc:
|
|
2326
|
+
# element self-declares inline except <dc:date>, whose ELEMENT prefix is
|
|
2327
|
+
# then unbound, and the identifier's ns0:scheme is out of scope too.
|
|
2328
|
+
EMBED_SCARRED_OPF = (
|
|
2329
|
+
'<?xml version="1.0" encoding="UTF-8"?>'
|
|
2330
|
+
'<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="ID1" '
|
|
2331
|
+
'version="2.0">'
|
|
2332
|
+
"<metadata>"
|
|
2333
|
+
'<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Hackers</dc:title>'
|
|
2334
|
+
'<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/" '
|
|
2335
|
+
'xmlns:ns0="http://www.idpf.org/2007/opf" ns0:role="aut" '
|
|
2336
|
+
'ns0:file-as="Levy, Steven">Steven Levy</dc:creator>'
|
|
2337
|
+
'<dc:identifier xmlns:dc="http://purl.org/dc/elements/1.1/" id="ID1" '
|
|
2338
|
+
'ns0:scheme="calibre">fccddb12-6dd3-4896-ab23-c676558ca98b</dc:identifier>'
|
|
2339
|
+
"<dc:date>2001-01-02</dc:date>"
|
|
2340
|
+
"</metadata>"
|
|
2341
|
+
'<manifest><item id="c1" href="c1.xhtml" '
|
|
2342
|
+
'media-type="application/xhtml+xml"/><item id="ncx" href="toc.ncx" '
|
|
2343
|
+
'media-type="application/x-dtbncx+xml"/></manifest>'
|
|
2344
|
+
'<spine toc="ncx"><itemref idref="c1"/></spine></package>'
|
|
2345
|
+
)
|
|
2346
|
+
|
|
2325
2347
|
|
|
2326
2348
|
class TestUnboundPrefix(unittest.TestCase):
|
|
2327
2349
|
"""Issue #9: the Calibre embed scar. One dc: element carries an
|
|
@@ -2366,3 +2388,39 @@ class TestUnboundPrefix(unittest.TestCase):
|
|
|
2366
2388
|
# the bound package parses and its unique-identifier resolves
|
|
2367
2389
|
ET.fromstring(opf)
|
|
2368
2390
|
self.assertFalse(ncx_uid_mismatch(dst))
|
|
2391
|
+
|
|
2392
|
+
def _build_embed_scar(self, td: str) -> tuple[Path, Path]:
|
|
2393
|
+
src, dst = Path(td) / "in.epub", Path(td) / "out.epub"
|
|
2394
|
+
with zipfile.ZipFile(src, "w") as z:
|
|
2395
|
+
z.writestr("mimetype", "application/epub+zip")
|
|
2396
|
+
z.writestr("OEBPS/c1.xhtml", CONTENT)
|
|
2397
|
+
z.writestr("OEBPS/toc.ncx", NCX_BAD)
|
|
2398
|
+
z.writestr("OEBPS/content.opf", EMBED_SCARRED_OPF)
|
|
2399
|
+
return src, dst
|
|
2400
|
+
|
|
2401
|
+
def test_embed_scar_element_and_attribute_bound(self):
|
|
2402
|
+
# Issue #22: one run binds both halves of the 9.7.0 scar. On the
|
|
2403
|
+
# specimen each fix alone left the other masked behind a still-fatal
|
|
2404
|
+
# package (1f/1e -> 1f/0e); together they parse it clean.
|
|
2405
|
+
with tempfile.TemporaryDirectory() as td:
|
|
2406
|
+
src, dst = self._build_embed_scar(td)
|
|
2407
|
+
report = repair_epub(src, dst, RepairFlags(unbound_prefix=True))
|
|
2408
|
+
self.assertEqual(report.fixes.get("unbound_prefixes_bound"), 2)
|
|
2409
|
+
with zipfile.ZipFile(dst) as z:
|
|
2410
|
+
opf = z.read("OEBPS/content.opf").decode()
|
|
2411
|
+
self.assertIn(
|
|
2412
|
+
'<dc:date xmlns:dc="http://purl.org/dc/elements/1.1/">2001-01-02</dc:date>',
|
|
2413
|
+
opf,
|
|
2414
|
+
)
|
|
2415
|
+
self.assertIn(
|
|
2416
|
+
'<dc:identifier xmlns:ns0="http://www.idpf.org/2007/opf" '
|
|
2417
|
+
'xmlns:dc="http://purl.org/dc/elements/1.1/" id="ID1"',
|
|
2418
|
+
opf,
|
|
2419
|
+
)
|
|
2420
|
+
ET.fromstring(opf)
|
|
2421
|
+
|
|
2422
|
+
def test_off_by_default_embed_scar(self):
|
|
2423
|
+
with tempfile.TemporaryDirectory() as td:
|
|
2424
|
+
src, dst = self._build_embed_scar(td)
|
|
2425
|
+
report = repair_epub(src, dst)
|
|
2426
|
+
self.assertNotIn("unbound_prefixes_bound", report.fixes)
|
|
@@ -423,16 +423,22 @@ def _fixtures() -> dict:
|
|
|
423
423
|
),
|
|
424
424
|
"--fix-unbound-prefix": (
|
|
425
425
|
{
|
|
426
|
-
"OEBPS/content.opf":
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
#
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
426
|
+
"OEBPS/content.opf": (
|
|
427
|
+
'<?xml version="1.0"?>'
|
|
428
|
+
'<package xmlns="http://www.idpf.org/2007/opf" '
|
|
429
|
+
'version="2.0" unique-identifier="id">'
|
|
430
|
+
# The 9.7.0 embed scar (issue #22): no xmlns:dc on
|
|
431
|
+
# <metadata>; the creator self-declares it, the
|
|
432
|
+
# identifier's ns0:scheme is out of scope, and dc:date's
|
|
433
|
+
# own element prefix is unbound.
|
|
434
|
+
"<metadata>"
|
|
435
|
+
'<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/" '
|
|
436
|
+
'xmlns:ns0="http://www.idpf.org/2007/opf" '
|
|
437
|
+
'ns0:role="aut">A</dc:creator>'
|
|
438
|
+
'<dc:identifier id="id" ns0:scheme="calibre">uuid-x</dc:identifier>'
|
|
439
|
+
"<dc:date>2001-01-02</dc:date>"
|
|
440
|
+
"</metadata>"
|
|
441
|
+
f"<manifest>{c1}</manifest><spine>{r1}</spine></package>"
|
|
436
442
|
),
|
|
437
443
|
"OEBPS/c1.xhtml": plain,
|
|
438
444
|
},
|
|
@@ -958,6 +958,22 @@ def _scarred_opf(scar: str, healthy: str = "") -> str:
|
|
|
958
958
|
)
|
|
959
959
|
|
|
960
960
|
|
|
961
|
+
def _embed_scarred_opf(scar: str, healthy: str = "") -> str:
|
|
962
|
+
"""The Hackers shape (issue #22): the metadata element carries no
|
|
963
|
+
xmlns:dc; every healthy dc: element self-declares one inline, exactly the
|
|
964
|
+
embed writer's habit, and the scarred element misses its declaration."""
|
|
965
|
+
return (
|
|
966
|
+
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
967
|
+
'<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="ID1" '
|
|
968
|
+
'version="2.0">\n'
|
|
969
|
+
" <metadata>\n"
|
|
970
|
+
f" {healthy}\n"
|
|
971
|
+
f" {scar}\n"
|
|
972
|
+
" </metadata>\n"
|
|
973
|
+
"</package>"
|
|
974
|
+
)
|
|
975
|
+
|
|
976
|
+
|
|
961
977
|
class TestFixUnboundPrefixes(unittest.TestCase):
|
|
962
978
|
SCAR = '<dc:identifier id="ID1" ns0:scheme="calibre">uuid-x</dc:identifier>'
|
|
963
979
|
HEALTHY = (
|
|
@@ -1125,6 +1141,155 @@ class TestFixUnboundPrefixes(unittest.TestCase):
|
|
|
1125
1141
|
self.assertEqual((twice, n2), (once, 0))
|
|
1126
1142
|
|
|
1127
1143
|
|
|
1144
|
+
_DC_DECL = 'xmlns:dc="http://purl.org/dc/elements/1.1/"'
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
class TestFixUnboundElementPrefixes(unittest.TestCase):
|
|
1148
|
+
"""Issue #22, the element half of the embed scar: the writer
|
|
1149
|
+
self-declares xmlns:dc on every dc: element but one, so that element's
|
|
1150
|
+
own ELEMENT prefix is unbound (RSC-016 'The prefix "dc" for element
|
|
1151
|
+
"dc:date" is not bound'). Same evidence rules as the attribute half;
|
|
1152
|
+
the dc: element's rule-2 fallback is the DC namespace itself."""
|
|
1153
|
+
|
|
1154
|
+
def test_unbound_element_prefix_bound_inline(self):
|
|
1155
|
+
# The Hackers specimen shape: healthy siblings self-declare, the
|
|
1156
|
+
# scarred element's declaration never made it in.
|
|
1157
|
+
doc = _embed_scarred_opf(
|
|
1158
|
+
"<dc:date>2001-01-02</dc:date>",
|
|
1159
|
+
f"<dc:title {_DC_DECL}>Hackers</dc:title>",
|
|
1160
|
+
)
|
|
1161
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1162
|
+
self.assertEqual(n, 1)
|
|
1163
|
+
self.assertIn(
|
|
1164
|
+
f"<dc:date {_DC_DECL}>2001-01-02</dc:date>",
|
|
1165
|
+
out,
|
|
1166
|
+
)
|
|
1167
|
+
ET.fromstring(out)
|
|
1168
|
+
|
|
1169
|
+
def test_element_and_attribute_scars_together(self):
|
|
1170
|
+
# The full scar: ns0:scheme unbound on the identifier AND dc:date's
|
|
1171
|
+
# element prefix unbound; one run binds both (2f -> 0f on the
|
|
1172
|
+
# specimen, where either alone masked the other).
|
|
1173
|
+
doc = _embed_scarred_opf(
|
|
1174
|
+
f'<dc:identifier {_DC_DECL} id="ID1" ns0:scheme="calibre">u</dc:identifier>'
|
|
1175
|
+
"<dc:date>2001-01-02</dc:date>",
|
|
1176
|
+
'<dc:creator xmlns:ns0="http://www.idpf.org/2007/opf" '
|
|
1177
|
+
f'{_DC_DECL} ns0:role="aut">A</dc:creator>',
|
|
1178
|
+
)
|
|
1179
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1180
|
+
self.assertEqual(n, 2)
|
|
1181
|
+
self.assertIn('xmlns:ns0="http://www.idpf.org/2007/opf"', out)
|
|
1182
|
+
self.assertIn(f"<dc:date {_DC_DECL}>", out)
|
|
1183
|
+
ET.fromstring(out)
|
|
1184
|
+
|
|
1185
|
+
def test_self_closing_element_prefix_bound(self):
|
|
1186
|
+
doc = _embed_scarred_opf("<dc:date/>", f"<dc:title {_DC_DECL}>H</dc:title>")
|
|
1187
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1188
|
+
self.assertEqual(n, 1)
|
|
1189
|
+
self.assertIn(f"<dc:date {_DC_DECL}/>", out)
|
|
1190
|
+
ET.fromstring(out)
|
|
1191
|
+
|
|
1192
|
+
def test_never_declared_dc_element_gets_dc_ns(self):
|
|
1193
|
+
# Rule 2 for elements: no declaration anywhere; a dc:-prefixed
|
|
1194
|
+
# element under an OPF-namespaced package is Dublin Core by the
|
|
1195
|
+
# spec, so the DC namespace itself is the deterministic URI.
|
|
1196
|
+
doc = _embed_scarred_opf("<dc:date>2001-01-02</dc:date>")
|
|
1197
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1198
|
+
self.assertEqual(n, 1)
|
|
1199
|
+
self.assertIn(f"<dc:date {_DC_DECL}>", out)
|
|
1200
|
+
ET.fromstring(out)
|
|
1201
|
+
|
|
1202
|
+
def test_element_prefix_uses_document_evidence(self):
|
|
1203
|
+
# Rule 1 outranks the dc-means-DC-NS intuition: the document's own
|
|
1204
|
+
# declarations say what its prefix means, and the fix matches them.
|
|
1205
|
+
doc = _embed_scarred_opf(
|
|
1206
|
+
"<dc:date>2001-01-02</dc:date>",
|
|
1207
|
+
'<dc:title xmlns:dc="http://foreign.example/not-dc">H</dc:title>',
|
|
1208
|
+
)
|
|
1209
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1210
|
+
self.assertEqual(n, 1)
|
|
1211
|
+
self.assertIn('<dc:date xmlns:dc="http://foreign.example/not-dc">', out)
|
|
1212
|
+
ET.fromstring(out)
|
|
1213
|
+
|
|
1214
|
+
def test_ambiguous_element_evidence_refuses(self):
|
|
1215
|
+
doc = _embed_scarred_opf(
|
|
1216
|
+
"<dc:date>2001-01-02</dc:date>",
|
|
1217
|
+
'<dc:title xmlns:dc="http://www.idpf.org/2007/opf">H</dc:title>'
|
|
1218
|
+
'<dc:publisher xmlns:dc="http://other.example/ns">P</dc:publisher>',
|
|
1219
|
+
)
|
|
1220
|
+
self.assertEqual(fix_unbound_prefixes(doc), (doc, 0))
|
|
1221
|
+
|
|
1222
|
+
def test_no_evidence_not_dc_refuses(self):
|
|
1223
|
+
doc = _embed_scarred_opf("<ns9:date>2001-01-02</ns9:date>")
|
|
1224
|
+
self.assertEqual(fix_unbound_prefixes(doc), (doc, 0))
|
|
1225
|
+
|
|
1226
|
+
def test_dc_element_without_opf_package_refuses(self):
|
|
1227
|
+
# Rule 2 needs the package itself to carry the OPF namespace; a
|
|
1228
|
+
# bare dc: spelling outside one means nothing deterministic.
|
|
1229
|
+
doc = _embed_scarred_opf("<dc:date>2001-01-02</dc:date>").replace(
|
|
1230
|
+
'xmlns="http://www.idpf.org/2007/opf" ', ""
|
|
1231
|
+
)
|
|
1232
|
+
self.assertEqual(fix_unbound_prefixes(doc), (doc, 0))
|
|
1233
|
+
|
|
1234
|
+
def test_ancestor_declaration_satisfies(self):
|
|
1235
|
+
# The Century Rain fixture's shape: xmlns:dc on <metadata> covers
|
|
1236
|
+
# every dc: element name below it; nothing to do.
|
|
1237
|
+
doc = _scarred_opf("<dc:date>2001-01-02</dc:date>")
|
|
1238
|
+
self.assertEqual(fix_unbound_prefixes(doc), (doc, 0))
|
|
1239
|
+
|
|
1240
|
+
def test_own_declaration_satisfies(self):
|
|
1241
|
+
doc = _embed_scarred_opf(f"<dc:date {_DC_DECL}>2001-01-02</dc:date>")
|
|
1242
|
+
self.assertEqual(fix_unbound_prefixes(doc), (doc, 0))
|
|
1243
|
+
|
|
1244
|
+
def test_nested_element_prefixes_each_bound(self):
|
|
1245
|
+
# The each-use-site contract the attribute half established: an
|
|
1246
|
+
# inner element's unbound prefix gets its own inline declaration
|
|
1247
|
+
# even though the outer's edit will scope over it.
|
|
1248
|
+
doc = _embed_scarred_opf("<dc:meta><dc:date>2001-01-02</dc:date></dc:meta>")
|
|
1249
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1250
|
+
self.assertEqual(n, 2)
|
|
1251
|
+
ET.fromstring(out)
|
|
1252
|
+
|
|
1253
|
+
def test_element_and_attribute_same_prefix_bound_once(self):
|
|
1254
|
+
# One declaration per prefix per start tag: an attribute sharing the
|
|
1255
|
+
# element's own unbound prefix never queues a second xmlns (the
|
|
1256
|
+
# code-review collision), and the element's Dublin Core identity
|
|
1257
|
+
# decides the URI for both.
|
|
1258
|
+
doc = _embed_scarred_opf('<dc:date dc:event="x">2001-01-02</dc:date>')
|
|
1259
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1260
|
+
self.assertEqual(n, 1)
|
|
1261
|
+
self.assertEqual(out.count("xmlns:dc="), 1)
|
|
1262
|
+
ET.fromstring(out)
|
|
1263
|
+
|
|
1264
|
+
def test_two_attributes_same_prefix_bound_once(self):
|
|
1265
|
+
# The attribute half's own variant of the same collision (it
|
|
1266
|
+
# emitted a duplicate xmlns attribute before the dedupe). The
|
|
1267
|
+
# Century Rain fixture declares xmlns:dc on <metadata>, so only
|
|
1268
|
+
# the two same-prefix attributes are unbound here.
|
|
1269
|
+
doc = _scarred_opf(
|
|
1270
|
+
'<dc:identifier id="ID1" ns0:x="1" ns0:y="2">u</dc:identifier>',
|
|
1271
|
+
'<dc:creator xmlns:ns0="http://www.idpf.org/2007/opf">A</dc:creator>',
|
|
1272
|
+
)
|
|
1273
|
+
out, n = fix_unbound_prefixes(doc)
|
|
1274
|
+
self.assertEqual(n, 1)
|
|
1275
|
+
# the sibling's own declaration plus the one bind (never two binds)
|
|
1276
|
+
self.assertEqual(out.count("xmlns:ns0="), 2)
|
|
1277
|
+
ET.fromstring(out)
|
|
1278
|
+
|
|
1279
|
+
def test_xml_prefix_never_flagged(self):
|
|
1280
|
+
doc = _embed_scarred_opf('<xml:stylesheet href="x"/>')
|
|
1281
|
+
self.assertEqual(fix_unbound_prefixes(doc), (doc, 0))
|
|
1282
|
+
|
|
1283
|
+
def test_idempotent(self):
|
|
1284
|
+
doc = _embed_scarred_opf(
|
|
1285
|
+
"<dc:date>2001-01-02</dc:date>",
|
|
1286
|
+
f"<dc:title {_DC_DECL}>Hackers</dc:title>",
|
|
1287
|
+
)
|
|
1288
|
+
once, _ = fix_unbound_prefixes(doc)
|
|
1289
|
+
twice, n2 = fix_unbound_prefixes(once)
|
|
1290
|
+
self.assertEqual((twice, n2), (once, 0))
|
|
1291
|
+
|
|
1292
|
+
|
|
1128
1293
|
class TestCssProtectedTags(unittest.TestCase):
|
|
1129
1294
|
def test_element_selector_protects(self):
|
|
1130
1295
|
self.assertIn("st", css_protected_tags("st { color: red }"))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|