Skip to content

Commit 9cbb83d

Browse files
committed
XML: retain QuickJS tag sources during copy
1 parent ef241a8 commit 9cbb83d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

external/qjs_xml_module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,19 @@ qjs_xml_node_tags_modify(JSContext *cx, JSValue obj, njs_str_t *name,
869869
}
870870

871871
node = qjs_xml_node(cx, v, NULL);
872-
JS_FreeValue(cx, v);
873872
if (node == NULL) {
873+
JS_FreeValue(cx, v);
874874
goto error;
875875
}
876876

877877
if (qjs_xml_tree_has_namespaces(node)) {
878+
JS_FreeValue(cx, v);
878879
JS_ThrowTypeError(cx, "setval[%u] has namespaces", i);
879880
goto error;
880881
}
881882

882883
node = xmlDocCopyNode(node, current->doc->doc, 1);
884+
JS_FreeValue(cx, v);
883885
if (node == NULL) {
884886
JS_ThrowInternalError(cx, "xmlDocCopyNode() failed");
885887
goto error;

test/xml/xml.t.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,20 @@ let modify_tsuite = {
592592
return xml.serializeToString(doc);
593593
},
594594
expected: `<root><child>value</child></root>` },
595+
{ doc: `<root></root>`,
596+
skip: () => !has_quickjs(),
597+
get: (doc) => {
598+
let values = [];
599+
600+
Object.defineProperty(values, '0', {
601+
get: () => xml.parse(`<child>value</child>`),
602+
});
603+
Object.defineProperty(values, 'length', {value: 1});
604+
605+
doc.root.$tags = values;
606+
return xml.serializeToString(doc);
607+
},
608+
expected: `<root><child>value</child></root>` },
595609
{ doc: `<root><target><old>value</old></target></root>`,
596610
skip: () => !has_quickjs(),
597611
get: (doc) => {

0 commit comments

Comments
 (0)