Skip to content

Commit

Permalink
Fixed a bug where text of XML element cannot be empty. (#3643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinming-Hu authored May 12, 2022
1 parent 0e68b12 commit fc2f7c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azure-storage-common/src/xml_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -288,7 +288,7 @@ namespace Azure { namespace Storage { namespace _internal {
auto context = static_cast<XmlWriterContext*>(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)});
Expand Down Expand Up @@ -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()));
}
Expand Down

0 comments on commit fc2f7c5

Please sign in to comment.