mirror of
https://github.com/storytold/photocraft.git
synced 2026-10-28 10:11:58 +01:00
A long run of '&' without a nearby ';' scanned to the end of the string for every '&' (quadratic). Adds a test with a 200k-ampersand description.
25 lines
1.1 KiB
Rust
25 lines
1.1 KiB
Rust
use photocraft_engine::file_cmds::read_file_info;
|
|
|
|
#[test]
|
|
fn numeric_character_references_are_decoded() {
|
|
let xmp = "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF><rdf:Description>\
|
|
<dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">Line one
Line two © & co A &#38;</rdf:li></rdf:Alt></dc:description>\
|
|
</rdf:Description></rdf:RDF></x:xmpmeta>";
|
|
let info = read_file_info(Some(xmp));
|
|
assert_eq!(info["description"], "Line one\nLine two © & co A &");
|
|
}
|
|
|
|
/// Many `&` with no `;` near them stay literal, and are scanned a bounded distance each (a
|
|
/// multi-megabyte XMP once made this quadratic).
|
|
#[test]
|
|
fn a_long_run_of_ampersands_without_semicolons_is_left_unchanged() {
|
|
let run = "&".repeat(200_000);
|
|
let xmp = format!(
|
|
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF><rdf:Description>\
|
|
<dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">{run}</rdf:li></rdf:Alt></dc:description>\
|
|
</rdf:Description></rdf:RDF></x:xmpmeta>"
|
|
);
|
|
let info = read_file_info(Some(&xmp));
|
|
assert_eq!(info["description"], run.as_str());
|
|
}
|