matrix-org / matrix-rich-text-editor

Matrix Rich Text Editor
https://matrix-org.github.io/matrix-rich-text-editor/
Apache License 2.0
83 stars 19 forks source link

Setting a an html/xml like content as markdown, returns empty text #910

Open Velin92 opened 6 months ago

Velin92 commented 6 months ago

While investigating this issue: https://github.com/element-hq/element-x-ios/issues/2265

We found out that when RTE is disabled which means that plain text mode is enabled and so markdown is parsed directly by our Rust markdown to html parser, any content that looks like html or xml is completely ignored and sicarded returning an empty message. I wrote a test case for it:

fn set_content_from_markdown_that_contains_xml() {
    let mut model = cm("|");
    model
        .set_content_from_markdown(&utf16(
            r#"<message id="1" to="123456789098765@lid" type="text">
        <enc v="2" type="pkmsg" count="[1,5]" >...CIPHERTEXT[Alice]...</enc>
  </message>"#,
        ))
        .unwrap();
    assert_eq!(
        tx(&model),
        r#"<message id="1" to="123456789098765@lid" type="text">
    <enc v="2" type="pkmsg" count="[1,5]" >...CIPHERTEXT[Alice]...</enc>
</message>|"#
    );

The tests fails with the following error:

panicked at 'assertion failed: `(left == right)`
  left: `"|"`,
 right: `"<message id=\"1\" to=\"123456789098765@lid\" type=\"text\">\n    <enc v=\"2\" type=\"pkmsg\" count=\"[1,5]\" >...CIPHERTEXT[Alice]...</enc>\n</message>|"`', crates/wysiwyg/src/tests/test_set_content.rs:251:5

The conversion fails here: https://github.com/matrix-org/matrix-wysiwyg/blob/fcfef8a6f59880de90156f3daa46c60b6328311b/crates/wysiwyg/src/composer_model/base.rs#L125 In fact the markdown to html conversion works, is the set_html of the parsed html that is not converted properly into out dom supported html and fails, giving us an empty dom/html