Skip to content

Commit e8dc60e

Browse files
committed
Change node value's parsing to concatenate instead of copy it every time
1 parent bf707de commit e8dc60e

File tree

1 file changed

+9
-1
lines changed
  • src/request_body_processor

1 file changed

+9
-1
lines changed

src/request_body_processor/xml.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class MSCSAXHandler {
7171
xml_data->nodes[xml_data->nodes.size()-1]->has_child = true;
7272
}
7373
xml_data->currpath.append(name);
74+
// set the current value empty
75+
// this is necessary because if there is any text between the tags (new line, etc)
76+
// it will be added to the current value
77+
xml_data->currval = "";
7478
}
7579

7680
void onEndElement(void * ctx, const xmlChar *localname) {
@@ -92,13 +96,17 @@ class MSCSAXHandler {
9296
}
9397
xml_data->nodes.pop_back();
9498
xml_data->node_depth--;
99+
xml_data->currval = "";
95100
}
96101

97102
void onCharacters(void *ctx, const xmlChar *ch, int len) {
98103
XMLNodes* xml_data = static_cast<XMLNodes*>(ctx);
99104
std::string content(reinterpret_cast<const char *>(ch), len);
100105

101-
xml_data->currval = content;
106+
// libxml2 SAX parser will call this function multiple times
107+
// during the parsing of a single node, if the value has multibyte
108+
// characters, so we need to concatenate the values
109+
xml_data->currval += content;
102110
}
103111
};
104112

0 commit comments

Comments
 (0)