Files
craft-anything/crates/formats/tests/sourcemap_annotation_spacing.rs
RRFZ 744e5c9838 Read source map annotations with optional marker spacing (R3.12) (#1731) (#1731)
A script's trailing sourceMappingURL annotation is found with no space, a tab or several spaces after the //#, //@ or /*# marker, as the source map standard allows; an annotation whose URL contains whitespace is ignored.
2026-11-12 12:13:49 +07:00

15 lines
683 B
Rust

use craft_anything_formats::sourcemap::find_source_mapping_url;
/// Standard annotations permit zero or several whitespace characters after the marker.
#[test]
fn annotation_marker_accepts_standard_whitespace() {
for marker in ["//#", "//@", "/*#"] {
for gap in ["", " ", "\t", " \t"] {
let end = if marker.starts_with("/*") { " */" } else { "" };
assert_eq!(find_source_mapping_url(&format!("{marker}{gap}sourceMappingURL=app.js.map{end}")), Some("app.js.map".into()));
}
}
assert_eq!(find_source_mapping_url("//# sourceMappingURL=two words.map"), None);
assert_eq!(find_source_mapping_url("//# other=app.js.map"), None);
}