diff --git a/sdk/storage/azure-storage-common/CHANGELOG.md b/sdk/storage/azure-storage-common/CHANGELOG.md index 85fac2ba62..637f3f7eda 100644 --- a/sdk/storage/azure-storage-common/CHANGELOG.md +++ b/sdk/storage/azure-storage-common/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +- Fixed a bug where text of XML element cannot be empty. + ### Other Changes ## 12.2.3 (2022-04-06) diff --git a/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/xml_wrapper.hpp b/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/xml_wrapper.hpp index 6aed398d9d..31c4fb14cb 100644 --- a/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/xml_wrapper.hpp +++ b/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/xml_wrapper.hpp @@ -19,17 +19,20 @@ namespace Azure { namespace Storage { namespace _internal { struct XmlNode final { - explicit XmlNode( - XmlNodeType type, - std::string name = std::string(), - std::string value = std::string()) - : Type(type), Name(std::move(name)), Value(std::move(value)) + explicit XmlNode(XmlNodeType type, std::string name = std::string()) + : Type(type), Name(std::move(name)) + { + } + + explicit XmlNode(XmlNodeType type, std::string name, std::string value) + : Type(type), Name(std::move(name)), Value(std::move(value)), HasValue(true) { } XmlNodeType Type; std::string Name; std::string Value; + bool HasValue = false; }; class XmlReader final { diff --git a/sdk/storage/azure-storage-common/src/xml_wrapper.cpp b/sdk/storage/azure-storage-common/src/xml_wrapper.cpp index f914421b68..4190240c45 100644 --- a/sdk/storage/azure-storage-common/src/xml_wrapper.cpp +++ b/sdk/storage/azure-storage-common/src/xml_wrapper.cpp @@ -203,7 +203,7 @@ namespace Azure { namespace Storage { namespace _internal { } case WS_XML_NODE_TYPE_END_ELEMENT: moveToNext(); - return XmlNode{XmlNodeType::EndTag, std::string()}; + return XmlNode{XmlNodeType::EndTag}; case WS_XML_NODE_TYPE_EOF: return XmlNode{XmlNodeType::End}; case WS_XML_NODE_TYPE_CDATA: @@ -288,7 +288,7 @@ namespace Azure { namespace Storage { namespace _internal { auto context = static_cast(m_context); if (node.Type == XmlNodeType::StartTag) { - if (!node.Value.empty()) + if (node.HasValue) { Write(XmlNode{XmlNodeType::StartTag, std::move(node.Name)}); Write(XmlNode{XmlNodeType::Text, std::string(), std::move(node.Value)}); @@ -576,7 +576,7 @@ namespace Azure { namespace Storage { namespace _internal { xmlTextWriterPtr writer = context->writer; if (node.Type == XmlNodeType::StartTag) { - if (node.Value.empty()) + if (!node.HasValue) { xmlTextWriterStartElement(writer, BadCast(node.Name.data())); }