bindery-cli 0.62.0__tar.gz → 0.62.1__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.62.0 → bindery_cli-0.62.1}/PKG-INFO +1 -1
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/patchnotes.md +32 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/pyproject.toml +1 -1
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/roadmap.md +1 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/spec.md +5 -3
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/__init__.py +1 -1
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/cli.py +15 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/epub.py +6 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/transforms.py +46 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_epub.py +36 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_flags_real_core.py +19 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_flags_wiring.py +1 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_transforms.py +65 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/uv.lock +1 -1
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/.github/FUNDING.yml +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/.github/workflows/ci.yml +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/.github/workflows/publish.yml +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/.gitignore +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/AGENTS.md +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/LICENSE +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/OBSERVE-RESEARCH.md +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/README.md +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/docs/screenshots/library-sweep.png +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/logo.svg +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/plugin/__init__.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/project.done +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/run_tests.sh +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/scripts/FastSweep.java +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/scripts/build_plugin.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/scripts/fast_sweep.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/__main__.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/audit.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/library.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/observe.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/pagination.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/reserialize.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/validate.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/src/bindery/watermark.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_audit.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_cli.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_comment_hyphens.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_contamination.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_cover_tocdrift.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_help.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_library.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_matcher_hardening.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_observe.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_pagination.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_plugin.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_reserialize.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_space_renames.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_spine_guard.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_validate.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_version.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_watermark.py +0 -0
- {bindery_cli-0.62.0 → bindery_cli-0.62.1}/tests/test_xml_hardening.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bindery-cli
|
|
3
|
-
Version: 0.62.
|
|
3
|
+
Version: 0.62.1
|
|
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,37 @@
|
|
|
1
1
|
# bindery-cli Patch Notes
|
|
2
2
|
|
|
3
|
+
## v0.62.1 (2026-11-04)
|
|
4
|
+
|
|
5
|
+
### --fix-double-colon-tags: the pseudo-tag escape, and the last fatal's repair
|
|
6
|
+
|
|
7
|
+
An XML name can carry at most one colon (the QName production is
|
|
8
|
+
`(NCName ':')? NCName`), so a pseudo-tag whose name contains `::` is
|
|
9
|
+
never markup -- every occurrence is unescaped author text, and the
|
|
10
|
+
parser dies on it with a fatal RSC-016. The Book of Debugging's C++
|
|
11
|
+
code samples carried exactly that: `std::vector<std::shared_ptr>` with
|
|
12
|
+
the template's closing bracket escaped as `>` but the pseudo-tag
|
|
13
|
+
itself raw, at `EPUB/xhtml/part3.xhtml:399`. It was the library's one
|
|
14
|
+
remaining fatal after the 2026-11-03 wave.
|
|
15
|
+
|
|
16
|
+
The new opt-in flag escapes both ends of the construct, restoring
|
|
17
|
+
exactly the text the author wrote. Real markup is unreachable by
|
|
18
|
+
construction: the double colon lives in the name grammar itself, so no
|
|
19
|
+
legal tag can match, and prose comparisons (`a < b`) never form the
|
|
20
|
+
shape. Nested templates escape inner-first until stable, and the
|
|
21
|
+
trailing `>`s of a fully-escaped nesting stay raw -- legal text that
|
|
22
|
+
renders as `>`. Live on the facility specimen: `1f/15e/0w -> 0f/14e/0w`,
|
|
23
|
+
the gate accepts, and the book opens again. The unmasked residue
|
|
24
|
+
(the OPF-030/048 uid-empty family, the XHTML 1.1 strictness findings
|
|
25
|
+
the fatal was masking, and the `<int>`/`<dbghelp.h>` header-name
|
|
26
|
+
pseudo-tags, which are legal QNames and ride the content-model lane
|
|
27
|
+
rather than this one) is the manual list the observatory tracks.
|
|
28
|
+
|
|
29
|
+
Also closes a spec.md drift the release audit noted: the four v0.62.0
|
|
30
|
+
flags join the structural-repairs inventory (now thirty) and this flag
|
|
31
|
+
joins the safe opt-ins (now five).
|
|
32
|
+
|
|
33
|
+
Suite: 887 tests.
|
|
34
|
+
|
|
3
35
|
## v0.62.0 (2026-11-03)
|
|
4
36
|
|
|
5
37
|
### The observatory batch: three predicate repairs and four new flags
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bindery-cli"
|
|
7
|
-
version = "0.62.
|
|
7
|
+
version = "0.62.1"
|
|
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 = [
|
|
@@ -56,6 +56,7 @@ The plugin vendors the core and never gates (the epubcheck latency ruling).
|
|
|
56
56
|
| 0.60 | The oracle budget scales on decimal MB and archive entry count (issue #24): the Summa Theologica (10,440,245 bytes = 9.96 binary MiB, 3,831 entries, 3,808 spine docs, 16,456 playOrder findings) is entry-count-bound, not bytes-bound -- measured 384s source and 445s candidate against the flat 300s its bytes computed (the binary 10 MiB divisor ate the size chunk; the book the docs call 10.4 MB never earned one) -- so every sweep double-timed-out and misfiled it as `(epubcheck timeout)`; the size term counts decimal MB now, the entry term adds +60s per started 500 entries above 1,000 (same 1800s cap), the book computes 720s, and a non-zip path falls back to size-only. epubcheck does police the playOrder contract (2 of the source's 6 RSC-005 error entries): default-pass candidate measures 0f/6e -> 0f/4e (accept), scoped `--all` candidate 0f/0e/0w | v0.60.0 |
|
|
57
57
|
| 0.61.1 | The hex-ref href crash and the sweep that survives it: `_NUMERIC_REF_RE` captured the hex ref's `x` into the digits group and `int('x2013', 16)` killed the first whole-library `--all` dry run (2026-11-03 observe lane; 36 hex-ref hrefs across 5 books, every one an external URL the decode reaches before the scheme check discards it; dormant since v0.58.0 because the resolver is opt-in-path-only); the fix strips the prefix before the int, and the sweep's repair loop gains the crash guard -- an unexpected per-book exception is that book's `error` verdict (`crash (Type): ...; not applied`), counted in the existing errors tally, instead of a run-killing traceback (the single-file verb keeps its traceback) | v0.61.1 |
|
|
58
58
|
| 0.62 | The observatory batch (the 2026-11-03 lane's answers): three predicate repairs -- the playOrder contract goes base-free (epubcheck polices sharing/distinctness/gaps, never the base; 107 no-op renumberings silenced), `fix_pagelist_class` inserts the collision-checked id beside the class (class-only made epubcheck demand the id it enabled; the 215-rejection poison), `fix_missing_title` fills the self-closed `<title/>` (the paired-fill branch was dead code; the 70-rejection poison) -- and four new flags for the never-triaged census codes: `--fix-package-version` (OPF-001; literal 1.0 only), `--fix-doctype` (HTM-004; present-but-forbidden declarations only, after the firing census killed insertion), `--prune-invalid-guide-refs` (OPF-032; declared-but-not-a-content-doc targets), `--fix-item-properties` (OPF-014; EPUB3-only, scripted/svg/remote-resources from a whole-book census) | v0.62.0 |
|
|
59
|
+
| 0.62.1 | `--fix-double-colon-tags`: the pseudo-tag escape for the last library fatal -- an XML name carries at most one colon, so a `::`-named pseudo-tag is never markup (fatal RSC-016; the Book of Debugging's C++ samples), and escaping both ends restores the author's text; nested templates escape inner-first, real markup is unreachable by construction; also closes the spec.md drift (the four v0.62.0 flags had not joined the inventory) | v0.62.1 |
|
|
59
60
|
|
|
60
61
|
## Open work
|
|
61
62
|
|
|
@@ -13,7 +13,7 @@ restyle, re-compress, or restructure content, and it does not attempt to fix arb
|
|
|
13
13
|
schema (RSC-005) violations, which are usually harmless to readers and not safely
|
|
14
14
|
mechanizable.
|
|
15
15
|
|
|
16
|
-
The deliberate exceptions to "semantics-preserving" come in opt-in groups. The
|
|
16
|
+
The deliberate exceptions to "semantics-preserving" come in opt-in groups. The thirty
|
|
17
17
|
**structural repairs** (`--fix-empty-body`, `--fix-missing-title`, `--fix-id-colons`,
|
|
18
18
|
`--fix-page-map`, `--strip-epub3-attrs`, `--downgrade-epub3-tags`,
|
|
19
19
|
`--unwrap-block-in-inline`, `--strip-invalid-value`, `--unwrap-illegal-tags`,
|
|
@@ -23,13 +23,15 @@ The deliberate exceptions to "semantics-preserving" come in opt-in groups. The t
|
|
|
23
23
|
`--fix-svg-dup-ids`, `--fix-duplicate-ids`, `--fix-cdata-terminator`,
|
|
24
24
|
`--fix-misnested-inline`,
|
|
25
25
|
`--fix-stray-close`, `--fix-unterminated-attr`, `--fix-unbound-prefix`,
|
|
26
|
-
`--fix-unique-identifier
|
|
26
|
+
`--fix-unique-identifier`, `--fix-package-version`, `--fix-doctype`,
|
|
27
|
+
`--prune-invalid-guide-refs`, `--fix-item-properties`) alter
|
|
27
28
|
markup structure or fabricate minimal content; the four
|
|
28
29
|
**lossy modes** (`--strip-pagination`, `--strip-broken-tags`, `--strip-watermarks`,
|
|
29
30
|
`--strip-stub-docs`) remove
|
|
30
31
|
content a converter injected rather than content the author wrote. A fourth group of
|
|
31
32
|
**safe opt-ins** (`--fix-ids`, `--add-img-alt`, `--strip-bad-attrs`,
|
|
32
|
-
`--escape-unknown-entities`) repairs without altering
|
|
33
|
+
`--escape-unknown-entities`, `--fix-double-colon-tags`) repairs without altering
|
|
34
|
+
visible markup, and
|
|
33
35
|
`--reserialize` re-parses still-malformed documents whole. The default pass runs
|
|
34
36
|
ONLY the five well-formedness transforms above, the NCX pipeline, and the mimetype
|
|
35
37
|
fix: nothing else. (v0.14–v0.16 briefly
|
|
@@ -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.62.
|
|
14
|
+
VERSION = "0.62.1"
|
|
15
15
|
__version__ = VERSION
|
|
16
16
|
|
|
17
17
|
from .epub import RepairReport, repair_epub # noqa: E402
|
|
@@ -113,6 +113,7 @@ def _flags_from_args(args: argparse.Namespace) -> RepairFlags:
|
|
|
113
113
|
doctype=args.fix_doctype or all_,
|
|
114
114
|
prune_guide_refs=args.prune_invalid_guide_refs or all_,
|
|
115
115
|
item_properties=args.fix_item_properties or all_,
|
|
116
|
+
double_colon_tags=args.fix_double_colon_tags or all_,
|
|
116
117
|
)
|
|
117
118
|
|
|
118
119
|
|
|
@@ -1688,6 +1689,20 @@ _REPAIR_FLAG_TABLE: dict[str, list[tuple[str, str, str]]] = {
|
|
|
1688
1689
|
"DOCTYPE carries an internal subset (which can declare custom "
|
|
1689
1690
|
"entities) are skipped wholesale.",
|
|
1690
1691
|
),
|
|
1692
|
+
(
|
|
1693
|
+
"fix_double_colon_tags",
|
|
1694
|
+
"escape unescaped pseudo-tags whose name carries :: (a fatal QName break)",
|
|
1695
|
+
"escape the < and > around pseudo-tags whose name contains a double "
|
|
1696
|
+
"colon -- an XML name can carry at most one colon (the QName "
|
|
1697
|
+
"production), so such a construct is never markup and the parser "
|
|
1698
|
+
"dies on it with a fatal RSC-016 (C++ code samples like "
|
|
1699
|
+
"`std::vector<std::shared_ptr>` whose converter escaped the "
|
|
1700
|
+
"trailing bracket but not the tag; the Book of Debugging's last "
|
|
1701
|
+
"library fatal). Escaping both ends restores exactly the text the "
|
|
1702
|
+
"author wrote. Real markup is unreachable by construction: the "
|
|
1703
|
+
"double colon lives in the name grammar itself. Nested templates "
|
|
1704
|
+
"escape inner-first until stable.",
|
|
1705
|
+
),
|
|
1691
1706
|
],
|
|
1692
1707
|
"structural repairs: markup and nesting": [
|
|
1693
1708
|
(
|
|
@@ -40,6 +40,7 @@ from .transforms import (
|
|
|
40
40
|
escape_unknown_entities,
|
|
41
41
|
fix_cdata_terminator,
|
|
42
42
|
fix_comment_double_hyphen,
|
|
43
|
+
fix_double_colon_tags,
|
|
43
44
|
fix_duplicate_ids,
|
|
44
45
|
fix_empty_body,
|
|
45
46
|
fix_id_colons,
|
|
@@ -308,6 +309,7 @@ class RepairFlags:
|
|
|
308
309
|
doctype: bool = False
|
|
309
310
|
prune_guide_refs: bool = False
|
|
310
311
|
item_properties: bool = False
|
|
312
|
+
double_colon_tags: bool = False
|
|
311
313
|
|
|
312
314
|
|
|
313
315
|
@dataclass
|
|
@@ -3074,6 +3076,10 @@ def repair_epub(
|
|
|
3074
3076
|
text, n = fix_missing_title(text)
|
|
3075
3077
|
if n:
|
|
3076
3078
|
counts["fix_missing_title"] = n
|
|
3079
|
+
if flags.double_colon_tags:
|
|
3080
|
+
text, n = fix_double_colon_tags(text)
|
|
3081
|
+
if n:
|
|
3082
|
+
counts["double_colon_tags_escaped"] = n
|
|
3077
3083
|
if flags.doctype:
|
|
3078
3084
|
text, n = fix_doctype(text, pkg_major)
|
|
3079
3085
|
if n:
|
|
@@ -718,6 +718,52 @@ def fix_missing_title(s: str) -> tuple[str, int]:
|
|
|
718
718
|
_EXTERNAL_TARGET_RE = re.compile(r"^(?:[a-zA-Z][\w+.-]*:|//)")
|
|
719
719
|
|
|
720
720
|
|
|
721
|
+
# --fix-double-colon-tags: an XML name can carry at most one colon (the QName
|
|
722
|
+
# production is (NCName ':')? NCName), so a pseudo-tag whose name contains
|
|
723
|
+
# `::` can never be markup -- every occurrence is unescaped author text, and
|
|
724
|
+
# the parser reads it as a fatal RSC-016 (the Book of Debugging's C++ code
|
|
725
|
+
# samples: `std::vector<std::shared_ptr>` with the template's closing bracket
|
|
726
|
+
# escaped as `>` but the pseudo-tag itself raw). Escaping both ends
|
|
727
|
+
# restores exactly the text the author wrote.
|
|
728
|
+
_DOUBLE_COLON_TAG_RE = re.compile(r"</?[A-Za-z_][\w.-]*(?:::[\w.-]+)+[^>]*?>")
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
@_outside_protected
|
|
732
|
+
def fix_double_colon_tags(s: str) -> tuple[str, int]:
|
|
733
|
+
"""Escape `<`/`>` around pseudo-tags whose name contains `::`.
|
|
734
|
+
|
|
735
|
+
Opt-in (--fix-double-colon-tags): it rewrites document bytes, though the
|
|
736
|
+
result renders exactly the text the author intended. The `::` lives in
|
|
737
|
+
the NAME grammar, which no real tag can carry (a legal QName holds at
|
|
738
|
+
most one colon), so real markup is unreachable by construction; prose
|
|
739
|
+
comparisons (`a < b`) never match because the name must start the
|
|
740
|
+
construct and carry the double colon. A nested template
|
|
741
|
+
(`std::vector<std::string>`) leaves the innermost pseudo-tag for the
|
|
742
|
+
next pass -- the sub runs until stable (capped), and the trailing
|
|
743
|
+
`>`s of a fully-escaped nesting stay raw, which is legal text. The
|
|
744
|
+
`[^>]*?` tail crosses a nested `<` on purpose and stops at the first
|
|
745
|
+
`>`: a `<b::c` with no closing `>` anywhere would run to the next
|
|
746
|
+
tag's end -- the same single-class runaway shape every tag matcher
|
|
747
|
+
here documents, and the gate rejects any escape that measures worse.
|
|
748
|
+
"""
|
|
749
|
+
count = 0
|
|
750
|
+
|
|
751
|
+
def repl(m: re.Match) -> str:
|
|
752
|
+
nonlocal count
|
|
753
|
+
count += 1
|
|
754
|
+
body = m.group(0)
|
|
755
|
+
# body[0] is the leading `<` (and the `/` of a closing construct
|
|
756
|
+
# stays): escape both ends, plus any raw & or nested < the tail
|
|
757
|
+
# crossed
|
|
758
|
+
return "<" + body[1:-1].replace("&", "&").replace("<", "<") + ">"
|
|
759
|
+
|
|
760
|
+
for _ in range(16):
|
|
761
|
+
s, n = _DOUBLE_COLON_TAG_RE.subn(repl, s)
|
|
762
|
+
if not n:
|
|
763
|
+
break
|
|
764
|
+
return s, count
|
|
765
|
+
|
|
766
|
+
|
|
721
767
|
@_outside_protected
|
|
722
768
|
def fix_id_colons(s: str) -> tuple[str, int]:
|
|
723
769
|
"""Translate illegal colons in `id="X:Y"` and matching internal `#X:Y`
|
|
@@ -3656,3 +3656,39 @@ class TestFlagItemPropertiesEndToEnd(unittest.TestCase):
|
|
|
3656
3656
|
out = z.read("OEBPS/content.opf").decode()
|
|
3657
3657
|
self.assertIn('properties="nav"', out)
|
|
3658
3658
|
self.assertNotIn("scripted", out)
|
|
3659
|
+
|
|
3660
|
+
|
|
3661
|
+
class TestFlagDoubleColonTagsEndToEnd(unittest.TestCase):
|
|
3662
|
+
"""--fix-double-colon-tags through the real repair: the Book of
|
|
3663
|
+
Debugging's C++ sample shape (the library's last fatal) escapes and
|
|
3664
|
+
the count lands in fixes."""
|
|
3665
|
+
|
|
3666
|
+
def test_repair_epub_escapes_the_pseudo_tag(self):
|
|
3667
|
+
opf = (
|
|
3668
|
+
'<?xml version="1.0"?>'
|
|
3669
|
+
'<package xmlns="http://www.idpf.org/2007/opf" version="2.0" '
|
|
3670
|
+
'unique-identifier="id"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/">'
|
|
3671
|
+
'<dc:identifier id="id">x</dc:identifier>'
|
|
3672
|
+
"<dc:title>t</dc:title><dc:language>en</dc:language></metadata>"
|
|
3673
|
+
'<manifest><item id="c1" href="c1.xhtml" '
|
|
3674
|
+
'media-type="application/xhtml+xml"/></manifest>'
|
|
3675
|
+
"<spine><itemref idref='c1'/></spine></package>"
|
|
3676
|
+
)
|
|
3677
|
+
doc = (
|
|
3678
|
+
'<?xml version="1.0"?><html xmlns="http://www.w3.org/1999/xhtml">'
|
|
3679
|
+
"<head><title>t</title></head><body><pre><code><span>"
|
|
3680
|
+
"std::vector<std::shared_ptr>> data;</span>"
|
|
3681
|
+
"</code></pre></body></html>"
|
|
3682
|
+
)
|
|
3683
|
+
with tempfile.TemporaryDirectory() as td:
|
|
3684
|
+
s, d = Path(td) / "in.epub", Path(td) / "out.epub"
|
|
3685
|
+
with zipfile.ZipFile(s, "w", zipfile.ZIP_DEFLATED) as z:
|
|
3686
|
+
z.writestr("mimetype", "application/epub+zip")
|
|
3687
|
+
z.writestr("OEBPS/content.opf", opf)
|
|
3688
|
+
z.writestr("OEBPS/c1.xhtml", doc)
|
|
3689
|
+
report = repair_epub(s, d, RepairFlags(double_colon_tags=True))
|
|
3690
|
+
self.assertEqual(report.fixes.get("double_colon_tags_escaped"), 1)
|
|
3691
|
+
with zipfile.ZipFile(d) as z:
|
|
3692
|
+
out = z.read("OEBPS/c1.xhtml").decode()
|
|
3693
|
+
self.assertIn("<std::shared_ptr>", out)
|
|
3694
|
+
self.assertNotIn("<std::shared_ptr>", out)
|
|
@@ -529,6 +529,19 @@ def _fixtures() -> dict:
|
|
|
529
529
|
},
|
|
530
530
|
"item_properties_added",
|
|
531
531
|
),
|
|
532
|
+
"--fix-double-colon-tags": (
|
|
533
|
+
{
|
|
534
|
+
"OEBPS/content.opf": _opf([c1], [r1]),
|
|
535
|
+
"OEBPS/c1.xhtml": (
|
|
536
|
+
'<?xml version="1.0"?><html '
|
|
537
|
+
'xmlns="http://www.w3.org/1999/xhtml">'
|
|
538
|
+
"<head><title>t</title></head><body><pre><code><span>"
|
|
539
|
+
"std::vector<std::shared_ptr>> data;</span>"
|
|
540
|
+
"</code></pre></body></html>"
|
|
541
|
+
),
|
|
542
|
+
},
|
|
543
|
+
"double_colon_tags_escaped",
|
|
544
|
+
),
|
|
532
545
|
}
|
|
533
546
|
|
|
534
547
|
|
|
@@ -759,6 +772,12 @@ class FlagEndToEndTests(unittest.TestCase):
|
|
|
759
772
|
self._fixes_for("--fix-item-properties")["item_properties_added"], 1
|
|
760
773
|
)
|
|
761
774
|
|
|
775
|
+
def test_fix_double_colon_tags(self):
|
|
776
|
+
self.assertGreaterEqual(
|
|
777
|
+
self._fixes_for("--fix-double-colon-tags")["double_colon_tags_escaped"],
|
|
778
|
+
1,
|
|
779
|
+
)
|
|
780
|
+
|
|
762
781
|
|
|
763
782
|
if __name__ == "__main__":
|
|
764
783
|
unittest.main()
|
|
@@ -55,6 +55,7 @@ DEST_TO_FIELD = {
|
|
|
55
55
|
"fix_doctype": "doctype",
|
|
56
56
|
"prune_invalid_guide_refs": "prune_guide_refs",
|
|
57
57
|
"fix_item_properties": "item_properties",
|
|
58
|
+
"fix_double_colon_tags": "double_colon_tags",
|
|
58
59
|
"strip_pagination": "strip_pagination",
|
|
59
60
|
"strip_broken_tags": "strip_brokentags",
|
|
60
61
|
"strip_watermarks": "strip_watermarks",
|
|
@@ -15,6 +15,7 @@ from bindery.transforms import (
|
|
|
15
15
|
escape_bare_amp,
|
|
16
16
|
escape_unknown_entities,
|
|
17
17
|
fix_cdata_terminator,
|
|
18
|
+
fix_double_colon_tags,
|
|
18
19
|
fix_duplicate_ids,
|
|
19
20
|
fix_empty_body,
|
|
20
21
|
fix_id_colons,
|
|
@@ -1581,3 +1582,67 @@ class TestFixDuplicateIds(unittest.TestCase):
|
|
|
1581
1582
|
|
|
1582
1583
|
if __name__ == "__main__":
|
|
1583
1584
|
unittest.main()
|
|
1585
|
+
|
|
1586
|
+
|
|
1587
|
+
class TestFixDoubleColonTags(unittest.TestCase):
|
|
1588
|
+
"""--fix-double-colon-tags: an XML name can carry at most one colon, so
|
|
1589
|
+
a pseudo-tag whose name contains `::` is never markup -- every
|
|
1590
|
+
occurrence is unescaped author text and the parser dies on it with a
|
|
1591
|
+
fatal RSC-016 (the Book of Debugging's C++ samples, the library's last
|
|
1592
|
+
fatal). Escaping both ends restores the author's text; real markup is
|
|
1593
|
+
unreachable because the double colon lives in the name grammar."""
|
|
1594
|
+
|
|
1595
|
+
def test_escapes_the_book_of_debugging_shape(self):
|
|
1596
|
+
doc = (
|
|
1597
|
+
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>t</title>'
|
|
1598
|
+
"</head><body><pre><code><span>std::vector"
|
|
1599
|
+
"<std::shared_ptr>> data;</span></code></pre></body></html>"
|
|
1600
|
+
)
|
|
1601
|
+
out, n = fix_double_colon_tags(doc)
|
|
1602
|
+
self.assertEqual(n, 1)
|
|
1603
|
+
self.assertIn("std::vector<std::shared_ptr>> data;", out)
|
|
1604
|
+
|
|
1605
|
+
def test_closing_pseudo_tags_escape_too(self):
|
|
1606
|
+
out, n = fix_double_colon_tags("<p>begin <b::c> x </b::c> end</p>")
|
|
1607
|
+
self.assertEqual(n, 2)
|
|
1608
|
+
self.assertIn("<b::c>", out)
|
|
1609
|
+
self.assertIn("</b::c>", out)
|
|
1610
|
+
|
|
1611
|
+
def test_real_tags_are_never_touched(self):
|
|
1612
|
+
doc = (
|
|
1613
|
+
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>t</title>'
|
|
1614
|
+
"</head><body><p>a:b</p><p>plain</p></body></html>"
|
|
1615
|
+
)
|
|
1616
|
+
self.assertEqual(fix_double_colon_tags(doc), (doc, 0))
|
|
1617
|
+
|
|
1618
|
+
def test_prose_comparison_never_matches(self):
|
|
1619
|
+
doc = (
|
|
1620
|
+
"<html><head><title>t</title></head><body><p>if a < b</p></body></html>"
|
|
1621
|
+
)
|
|
1622
|
+
self.assertEqual(fix_double_colon_tags(doc), (doc, 0))
|
|
1623
|
+
|
|
1624
|
+
def test_nested_template_escapes_inner_first_then_outer(self):
|
|
1625
|
+
# `std::vector<std::string>` fully raw: the first pass escapes the
|
|
1626
|
+
# innermost construct, the second the outer one; the trailing `>`s
|
|
1627
|
+
# stay raw, which is legal text
|
|
1628
|
+
doc = (
|
|
1629
|
+
"<html><head><title>t</title></head><body><p>x"
|
|
1630
|
+
"<std::vector<std::string>>y</p></body></html>"
|
|
1631
|
+
)
|
|
1632
|
+
out, n = fix_double_colon_tags(doc)
|
|
1633
|
+
# one pass suffices: the tail crosses the nested `<` and the match
|
|
1634
|
+
# ends at the first raw `>`; the second trailing `>` stays raw,
|
|
1635
|
+
# which is legal text and renders as `>`
|
|
1636
|
+
self.assertEqual(n, 1)
|
|
1637
|
+
self.assertIn("x<std::vector<std::string>>y", out)
|
|
1638
|
+
# the result carries no raw `<` from the pseudo-tags
|
|
1639
|
+
self.assertNotIn("<std::", out)
|
|
1640
|
+
|
|
1641
|
+
def test_triple_colon_name_escapes(self):
|
|
1642
|
+
out, n = fix_double_colon_tags("<p><a::b::c></p>")
|
|
1643
|
+
self.assertEqual(n, 1)
|
|
1644
|
+
self.assertIn("<a::b::c>", out)
|
|
1645
|
+
|
|
1646
|
+
def test_escaped_constructs_are_stable(self):
|
|
1647
|
+
doc = "<p>std::vector<std::shared_ptr>> data;</p>"
|
|
1648
|
+
self.assertEqual(fix_double_colon_tags(doc), (doc, 0))
|
|
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
|
|
File without changes
|