DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge storytold/main into PR #1952
Brandon Thomasdfc0b19e7a5c
diff --cc crates/textimport/src/tagged.rsindex e903e98fd,c71032fa6..fc0d6a58d--- a/crates/textimport/src/tagged.rs+++ b/crates/textimport/src/tagged.rs@@@ -281,16 -289,28 +292,38 @@@ mod testsassert_eq!(import("<ASCII-WIN>\r\n<ParaStyle:Body>A<0xD83D>B<0xDE00>C".as_bytes()).unwrap().story.text, "ABC");}+ /// A style name is read back exactly as the exporter wrote it, spaces included.+ #[test]+ fn style_names_keep_leading_and_trailing_spaces() {+ let i = import("<ASCII-WIN>\r\n<Version:7>\r\n<ParaStyle:Body ><CharStyle: Em >Hello<CharStyle:>".as_bytes()).unwrap();+ assert_eq!(i.story.paras[0].style, "Body ");+ assert_eq!(i.story.char_format_at(2).style, " Em ");+ assert_eq!(i.para_styles[0].name, "Body ");+ assert_eq!(i.char_styles[0].name, " Em ");+ }++ /// A style defined with spaces in its name keeps them, so a paragraph that uses the name matches.+ #[test]+ fn defined_style_names_keep_leading_and_trailing_spaces() {+ let src =+ "<ASCII-WIN>\r\n<DefineParaStyle:Body =<cSize:12>><DefineCharStyle: Em =<cSize:12>><ParaStyle:Body ><CharStyle: Em >Hello<CharStyle:>";+ let i = import(src.as_bytes()).unwrap();+ assert_eq!(i.para_styles.len(), 1);+ assert_eq!(i.para_styles[0].name, "Body ");+ assert_eq!(i.char_styles.len(), 1);+ assert_eq!(i.char_styles[0].name, " Em ");+ }++ /// `from_str_radix` accepts a leading `+`, so `<0x+41>` inserted an 'A'. A signed or empty+ /// code is not a code point tag and is skipped.+ #[test]+ fn a_signed_hex_code_tag_is_skipped() {+ for t in ["<0x+41>", "<0x-41>", "<0x>", "<0xZZ>"] {+ let src = format!("<ASCII-WIN>\r\n<ParaStyle:Body>A{t}B");+ assert_eq!(import(src.as_bytes()).unwrap().story.text, "AB", "{t}");+ }+ }+/// A size does not have to be non-finite to be nonsense: a file can hold `1e300`, `0` or a/// negative, and tagged text took all three and set them on the text (#1593). They are now/// dropped, as RTF and DOCX already dropped them, so the text keeps its style's size.