Skip to content

Node::set_content failing (and clearing content) without returning Err #141

Description

@insiderscore-jeff

This may be a bug in libxml itself, but if you call set_content with an ampersand (&) that isn't & it treats it at an entity, and if that entity is unknown/invalid, it will print out "error: unterminated entity reference" on stderr, and will set the node content to blank string. The concerning thing is that set_content is not returning Err.

libxml = "0.3"

use libxml::tree::*;


fn main() {
    // induce set content bug in set_content
    let mut d = Document::new().unwrap();
    let mut n = Node::new("span", None, &d).unwrap();

    n.set_content("Testing").unwrap();
    let s = n.get_content();
    assert_eq!(s, "Testing");

    n.set_content("Testing & Breaking").unwrap();
    let s = n.get_content();
    assert_eq!(s, "Testing & Breaking");
}

output:

 Running `target/debug/ctest`
error : unterminated entity reference        Breaking
thread 'main' panicked at src/main.rs:15:5:
assertion `left == right` failed
  left: ""
 right: "Testing & Breaking"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions