Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_to_end breaks NsReader #597

Open
roblabla opened this issue May 2, 2023 · 1 comment · May be fixed by #598
Open

read_to_end breaks NsReader #597

roblabla opened this issue May 2, 2023 · 1 comment · May be fixed by #598
Labels
bug namespaces Issues related to namespaces support

Comments

@roblabla
Copy link

roblabla commented May 2, 2023

Heyo,

The NsReader::read_to_end seems to break its ability to resolve namespaces. This makes sense looking at its implementation: It simply delegates to the underlying readers' implementation, without updating its NamespaceResolver:

pub fn read_to_end(&mut self, end: QName) -> Result<Span> {
// According to the https://www.w3.org/TR/xml11/#dt-etag, end name should
// match literally the start name. See `Self::check_end_names` documentation
self.reader.read_to_end(end)
}

Here's a reproducer:

    #[test]
    fn repro2() {
        const S: &'static str = r#"
<?xml version="1.0" encoding="UTF-8"?>
<oval_definitions xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5">

    <tests>
        <xmlfilecontent_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
        </xmlfilecontent_test>
        <xmlfilecontent_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
        </xmlfilecontent_test>
    </tests>
    <objects/>
</oval_definitions>"#;

        let mut reader = quick_xml::NsReader::from_str(S);
        let (ns, ev) = loop {
            let (ns, ev) = reader.read_resolved_event().unwrap();
            match ev {
                quick_xml::events::Event::Start(v) if v.local_name().as_ref() == b"xmlfilecontent_test" => {
                    reader.read_to_end(v.name()).unwrap();
                },
                quick_xml::events::Event::Empty(v) if v.local_name().as_ref() == b"objects" => break (ns, v),
                _ => (),
            }
        };
        assert_eq!(ns, quick_xml::name::ResolveResult::Bound(quick_xml::name::Namespace(b"http://oval.mitre.org/XMLSchema/oval-definitions-5")));
    }
@Mingun
Copy link
Collaborator

Mingun commented May 2, 2023

Yes, this is a bug, we should pop the namespace before the returning from the read_to_end() method.

@Mingun Mingun added bug namespaces Issues related to namespaces support labels May 2, 2023
Mingun added a commit to Mingun/quick-xml that referenced this issue May 2, 2023
@Mingun Mingun linked a pull request May 2, 2023 that will close this issue
Mingun added a commit to Mingun/quick-xml that referenced this issue Jun 10, 2023
failures (25):
  ns_reader.rs (24):
    reader::ns_reader::read_text::cdata
    reader::ns_reader::read_text::comment
    reader::ns_reader::read_text::decl
    reader::ns_reader::read_text::doctype
    reader::ns_reader::read_text::empty
    reader::ns_reader::read_text::pi
    reader::ns_reader::read_text::start
    reader::ns_reader::read_text::text

    reader::ns_reader::read_to_end::cdata
    reader::ns_reader::read_to_end::comment
    reader::ns_reader::read_to_end::decl
    reader::ns_reader::read_to_end::doctype
    reader::ns_reader::read_to_end::empty
    reader::ns_reader::read_to_end::pi
    reader::ns_reader::read_to_end::start
    reader::ns_reader::read_to_end::text

    reader::ns_reader::read_to_end_into::cdata
    reader::ns_reader::read_to_end_into::comment
    reader::ns_reader::read_to_end_into::decl
    reader::ns_reader::read_to_end_into::doctype
    reader::ns_reader::read_to_end_into::empty
    reader::ns_reader::read_to_end_into::pi
    reader::ns_reader::read_to_end_into::start
    reader::ns_reader::read_to_end_into::text
  issues.rs (1)
    issue597
Mingun added a commit to Mingun/quick-xml that referenced this issue Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug namespaces Issues related to namespaces support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants