Skip to content

Commit bc08d87

Browse files
authored
fix XML encoding of text value (#200)
1 parent 49e578d commit bc08d87

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

include/miniocpp/utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ std::string Join(const std::vector<std::string>& values,
9595
// EncodePath does URL encoding of path. It also normalizes multiple slashes.
9696
std::string EncodePath(const std::string& path);
9797

98+
// XMLEncode does XML encoding of value.
99+
std::string XMLEncode(const std::string& value);
100+
98101
// Sha256hash computes SHA-256 of data and return hash as hex encoded value.
99102
std::string Sha256Hash(std::string_view str);
100103

src/baseclient.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ RemoveObjectsResponse BaseClient::RemoveObjects(RemoveObjectsApiArgs args) {
14591459
if (args.quiet) ss << "<Quiet>true</Quiet>";
14601460
for (auto& object : args.objects) {
14611461
ss << "<Object>";
1462-
ss << "<Key>" << object.name << "</Key>";
1462+
ss << "<Key>" << utils::XMLEncode(object.name) << "</Key>";
14631463
if (!object.version_id.empty()) {
14641464
ss << "<VersionId>" << object.version_id << "</VersionId>";
14651465
}

src/utils.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <map>
5757
#include <memory>
5858
#include <ostream>
59+
#include <pugixml.hpp>
5960
#include <regex>
6061
#include <sstream>
6162
#include <streambuf>
@@ -222,6 +223,14 @@ std::string EncodePath(const std::string& path) {
222223
return out;
223224
}
224225

226+
std::string XMLEncode(const std::string& value) {
227+
pugi::xml_document doc;
228+
doc.append_child(pugi::node_pcdata).set_value(value);
229+
std::ostringstream out;
230+
doc.print(out);
231+
return out.str();
232+
}
233+
225234
std::string Sha256Hash(std::string_view str) {
226235
EVP_MD_CTX* ctx = EVP_MD_CTX_create();
227236
if (ctx == nullptr) {

0 commit comments

Comments
 (0)