Escape XML metacharacters in EPUB metadata and page titles - #2270
Merged
Merged
Conversation
The EPUB templates interpolated project, version, language, author and page-title values straight into XHTML and into the OPF package document, which is written verbatim without the numeric-entity pass applied to generated pages. A value such as "A & B" or "AT&T" therefore produced a bare ampersand in content.opf and in every page header, making the EPUB unparseable by any XHTML/XML reader. Escape those values with h/1, matching what generated page content and the nav/manifest ids already do.
|
📦 Docs artifacts are ready: https://github.com/elixir-lang/ex_doc/actions/runs/35255996247/artifacts/10517518698 |
Member
|
💚 💙 💜 💛 ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OEBPS/content.opfis written verbatim, without the numeric-entity pass that is applied to generated pages, and the EPUB templates interpolatedproject,version,language, author names and page titles into it unescaped. The same unescaped values were also written into the<title>element of every page header.Any of those values containing
&,<or>therefore produced a bare metacharacter in an XML document. Withproject: "A & B",content.opfcontains:That is a fatal well-formedness error —
:xmerl_scanreports{:error_scanning_entity_ref, ...}and readers reject the file outright, so the whole EPUB fails to open.authors: ["AT&T"]fails the same way, as does any extra page whose heading contains&, since the heading is used as the page<title>.Changes
lib/ex_doc/formatter/epub/templates/content_template.eex— escapeproject,version,language, author names and static-file hrefs withh/1.lib/ex_doc/formatter/epub/templates/title_template.eex— escape the cover pageprojectandversion.lib/ex_doc/formatter/epub/templates/head_template.eex— escape the pagetitle,project,versionandlanguage.test/ex_doc/formatter/epub_test.exs— new test covering the package document, the cover page and a generated extra page; each document is parsed with:xmerl_scan, so malformed XML fails the test.test/fixtures/ExtraPageWithAmpersand.md— fixture with&in its heading.This follows the pattern of #2269, which escaped the manifest/nav ids and hrefs but left the metadata and page-title values untouched.
Validation
mix compile --warnings-as-errors— cleanmix format --check-formatted— cleanmix test— 1 doctest, 457 tests, 0 failures (456 tests before this change)Reverting only the three templates makes the new test fail with
{:fatal, {:error_scanning_entity_ref, ..., {:line, 3}, {:col, 46}}}, confirming the test exercises the defect rather than merely passing alongside it.