Skip to content

Commit b19a3fe

Browse files
committed
Do not set optional xml.Node attrs to empty string
1 parent 37bf64c commit b19a3fe

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

base/src/xml.ext.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ static unsigned char* copy_with_xml_escape(unsigned char *dst, B_str src, int es
6969
}
7070

7171
// Helper function to collect text from consecutive TEXT and CDATA nodes
72-
// Returns the combined string and updates the node pointer to the first non-text node
72+
// Returns the combined string (or NULL if there is no text/CDATA content) and
73+
// updates the node pointer to the first non-text node
7374
// Note: cur_ptr is passed by reference (pointer to pointer) so we can update the caller's pointer
7475
// to skip past all consumed text/CDATA nodes
7576
static B_str collect_text_cdata_nodes(xmlNodePtr *cur_ptr) {
7677
xmlNodePtr cur = *cur_ptr;
7778
if (!cur || (cur->type != XML_TEXT_NODE && cur->type != XML_CDATA_SECTION_NODE)) {
78-
return to$str("");
79+
return NULL;
7980
}
8081

8182
// Count total length of combined text and CDATA nodes
@@ -106,7 +107,7 @@ static B_str collect_text_cdata_nodes(xmlNodePtr *cur_ptr) {
106107
}
107108

108109
*cur_ptr = cur;
109-
return to$str("");
110+
return NULL;
110111
}
111112

112113
xmlQ_Node $NodePtr2Node(xmlNodePtr node) {

test/stdlib_tests/src/test_xml.act

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@ def _test_xml_namespace_attributes_undefined():
182182
def _test_xml_repr():
183183
test_xml = """<data xmlns="http://default"><a xmlns:ns="http://foo" ns:operation="remove"><ns:b ns:type="element">text</ns:b></a></data>"""
184184
d = xml.decode(test_xml)
185-
testing.assertEqual(repr(d), "xml.Node('data', nsdefs=[(None, 'http://default')], children=[xml.Node('a', nsdefs=[('ns', 'http://foo')], attributes=[('ns:operation', 'remove')], children=[xml.Node('b', prefix='ns', attributes=[('ns:type', 'element')], text='text')])])")
185+
testing.assertEqual(repr(d), "xml.Node(tag='data', nsdefs=[(None, 'http://default')], children=[xml.Node(tag='a', nsdefs=[('ns', 'http://foo')], attributes=[('ns:operation', 'remove')], children=[xml.Node(tag='b', prefix='ns', attributes=[('ns:type', 'element')], text='text')])])")

0 commit comments

Comments
 (0)