mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-19 14:00:52 +01:00
Replays #591–#596. The HTML scanner reads rel token lists, decodes asset URLs once, keeps script and title text through lookalike closing tags, and skips raw-text elements, markup inside attribute values and custom tag names. Co-authored-by: Afloat <132809511+Afloat16@users.noreply.github.com>
16 lines
896 B
Rust
16 lines
896 B
Rust
use craft_anything_js::html::scan_html;
|
|
fn decode_entities(value: &str) -> String {
|
|
scan_html(&format!("<script src=\"{value}\"></script>")).scripts[0].src.clone().unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn regression_asset_references_decode_once() {
|
|
let f = scan_html(r#"<script src="/app.js?a=1&b=2/3&quot;"></script><link rel="modulepreload" href="/modules/main.js">"#);
|
|
assert_eq!(f.scripts[0].src.as_deref(), Some("/app.js?a=1&b=2/3""));
|
|
assert_eq!(f.preloads, ["/modules/main.js"]);
|
|
assert_eq!(decode_entities("&unknown; &#x; &#not; &amp; 🙂"), "&unknown; &#x; &#not; & 🙂");
|
|
assert_eq!(decode_entities("� � � €"), "� � � €");
|
|
assert_eq!(decode_entities("/app.js /modules.js"), "/app.js /modules.js");
|
|
assert_eq!(decode_entities(&format!("&#{}47;app.js", "0".repeat(80))), "/app.js");
|
|
}
|