8000 `esi:include` self-closing tags are broken · Issue #281 · wilsonzlin/minify-html · GitHub
[go: up one dir, main page]

Skip to content

esi:include self-closing tags are broken #281

Open

Description

@FalkWoldmann

Edge Side Includes (ESI) markup such as <esi:include src="..." /> is stripped and processed by a CDN/edge proxy before a browser ever sees it (see ESI Language Specification 1.0 §3.1), which specifies ESI elements as XML and include as an empty element with no closing tag. This markup is common in HTML served through Akamai/Fastly-style edge proxies.

Per the WHATWG HTML parsing spec, the trailing / on a non-void, non-foreign (non-SVG/MathML) element is not actually a self-closing indicator, so minify-html currently parses <esi:include src="..." /> as an ordinary opening tag that stays open until a matching </esi:include> is found. Since that closing tag never appears in real-world markup, the element swallows all following sibling content as its own children, silently corrupting the document structure.

Repro

use minify_html::{minify, Cfg};

let html = br#"<div><esi:include src="/a" /><span>after</span></div>"#;
let out = minify(html, &Cfg::new());
println!("{}", String::from_utf8(out).unwrap());

Actual: <div><esi:include src=/a><span>after</span> — the <span> becomes a child of esi:include, and both the esi:include and outer div end up with no closing tags at all.

Expected: The self-closing esi:include tag (and its attributes) should be preserved verbatim, at least behind an opt-in config flag, so ESI-annotated HTML can be minified without breaking the edge proxy's ability to parse it.

Happy to submit a PR with a fix (adding a preserve_esi_include_tags Cfg option) if that approach sounds reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0