1
0
mirror of https://github.com/minio/minio-cpp.git synced 2026-01-26 04:01:32 +03:00

fix XML encoding of text value (#200)

This commit is contained in:
Foster
2026-01-11 09:48:31 +05:00
committed by GitHub
parent 49e578d286
commit bc08d87a8a
3 changed files with 13 additions and 1 deletions

View File

@@ -95,6 +95,9 @@ std::string Join(const std::vector<std::string>& values,
// EncodePath does URL encoding of path. It also normalizes multiple slashes.
std::string EncodePath(const std::string& path);
// XMLEncode does XML encoding of value.
std::string XMLEncode(const std::string& value);
// Sha256hash computes SHA-256 of data and return hash as hex encoded value.
std::string Sha256Hash(std::string_view str);

View File

@@ -1459,7 +1459,7 @@ RemoveObjectsResponse BaseClient::RemoveObjects(RemoveObjectsApiArgs args) {
if (args.quiet) ss << "<Quiet>true</Quiet>";
for (auto& object : args.objects) {
ss << "<Object>";
ss << "<Key>" << object.name << "</Key>";
ss << "<Key>" << utils::XMLEncode(object.name) << "</Key>";
if (!object.version_id.empty()) {
ss << "<VersionId>" << object.version_id << "</VersionId>";
}

View File

@@ -56,6 +56,7 @@
#include <map>
#include <memory>
#include <ostream>
#include <pugixml.hpp>
#include <regex>
#include <sstream>
#include <streambuf>
@@ -222,6 +223,14 @@ std::string EncodePath(const std::string& path) {
return out;
}
std::string XMLEncode(const std::string& value) {
pugi::xml_document doc;
doc.append_child(pugi::node_pcdata).set_value(value);
std::ostringstream out;
doc.print(out);
return out.str();
}
std::string Sha256Hash(std::string_view str) {
EVP_MD_CTX* ctx = EVP_MD_CTX_create();
if (ctx == nullptr) {