From e8dc60ee06a82a73d9de1bed4e4759ba20c815fe Mon Sep 17 00:00:00 2001 From: Ervin Hegedus Date: Mon, 28 Apr 2025 22:34:26 +0200 Subject: [PATCH] Change node value's parsing to concatenate instead of copy it every time --- src/request_body_processor/xml.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/request_body_processor/xml.cc b/src/request_body_processor/xml.cc index 0f48750c..c85801a5 100644 --- a/src/request_body_processor/xml.cc +++ b/src/request_body_processor/xml.cc @@ -71,6 +71,10 @@ class MSCSAXHandler { xml_data->nodes[xml_data->nodes.size()-1]->has_child = true; } xml_data->currpath.append(name); + // set the current value empty + // this is necessary because if there is any text between the tags (new line, etc) + // it will be added to the current value + xml_data->currval = ""; } void onEndElement(void * ctx, const xmlChar *localname) { @@ -92,13 +96,17 @@ class MSCSAXHandler { } xml_data->nodes.pop_back(); xml_data->node_depth--; + xml_data->currval = ""; } void onCharacters(void *ctx, const xmlChar *ch, int len) { XMLNodes* xml_data = static_cast(ctx); std::string content(reinterpret_cast(ch), len); - xml_data->currval = content; + // libxml2 SAX parser will call this function multiple times + // during the parsing of a single node, if the value has multibyte + // characters, so we need to concatenate the values + xml_data->currval += content; } };