]> Repositorios git - scryer-prolog.git/commitdiff
load_xml was returning a single term instead of a list of nodes
authorno382001 <[email protected]>
Tue, 3 Mar 2026 11:34:31 +0000 (12:34 +0100)
committerno382001 <[email protected]>
Tue, 10 Mar 2026 11:20:34 +0000 (12:20 +0100)
src/machine/system_calls.rs
tests-pl/issue3256.pl [new file with mode: 0644]
tests/scryer/issues.rs

index edd08cb5d9bc8bbacdeb11e8f1c2366e22ae2737..7453fd33110c45d36bea861fda3cc85b0fc5749e 100644 (file)
@@ -8450,7 +8450,12 @@ impl Machine {
             match roxmltree::Document::parse(&string.as_str()) {
                 Ok(doc) => {
                     let result = self.xml_node_to_term(doc.root_element())?;
-                    unify!(self.machine_st, self.machine_st.registers[2], result);
+                    let list = sized_iter_to_heap_list(
+                        &mut self.machine_st.heap,
+                        1, // just one root element
+                        std::iter::once(result),
+                    )?;
+                    unify!(self.machine_st, self.machine_st.registers[2], list);
                 }
                 _ => {
                     self.machine_st.fail = true;
diff --git a/tests-pl/issue3256.pl b/tests-pl/issue3256.pl
new file mode 100644 (file)
index 0000000..77e0bcf
--- /dev/null
@@ -0,0 +1,5 @@
+:- use_module(library(sgml)).
+
+test :- load_xml("<foo><bar>hello</bar></foo>", Es, []), write(Es).
+
+:- initialization(test).
index cb32174647fbada3682f1fc6ddf1d8ae6a44e63e..10ca8e240f05c176d974195fd42a51c4e00af776 100644 (file)
@@ -20,6 +20,15 @@ fn issue2588_load_html() {
     load_module_test("tests-pl/issue2588.pl", "[element(html,[],[element(head,[],[element(title,[],[[H,e,l,l,o,!]])]),element(body,[],[])])]");
 }
 
+#[test]
+#[cfg_attr(miri, ignore = "unsupported operation when isolation is enabled")]
+fn issue3256_load_xml_returns_list() {
+    load_module_test(
+        "tests-pl/issue3256.pl",
+        "[element(foo,[],[element(bar,[],[[h,e,l,l,o]])])]",
+    );
+}
+
 #[test]
 #[cfg_attr(miri, ignore = "unsupported operation when isolation is enabled")]
 fn issue2949_load_html() {