Skip to content

Commit

Permalink
Erase all xmlns: and xs: attributes when reading packs (#695) (#1140)
Browse files Browse the repository at this point in the history
* Erase all xmlns: and xs: attributes when reading packs
no need in that info (we do not write packs back)

Co-authored-by: Evgueni Driouk <[email protected]>
Co-authored-by: Daniel Brondani <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2023
1 parent dca662b commit c14b5f1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libs/rtemodel/src/RtePackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,12 @@ RteItem* RtePackage::CreateItem(const std::string& tag)
void RtePackage::Construct()
{
// remove attributes that we do not need:
RemoveAttribute("xmlns:xs");
RemoveAttribute("xs:noNamespaceSchemaLocation");
EraseAttributes("xmlns:*");
EraseAttributes("xs:*");
// some XML readers strip namespaces
RemoveAttribute("xs");
RemoveAttribute("noNamespaceSchemaLocation");
RemoveAttribute("schemaLocation");

if (m_releases) {
AddAttribute("version", m_releases->GetVersionString());
Expand Down
8 changes: 8 additions & 0 deletions libs/xmltree/include/XmlItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ class XmlItem
*/
bool RemoveAttribute(const std::string& name);

/**
* @brief removes several attributes matching given pattern
* @param pattern attribute pattern to remove
* @return true if at least one attribute is removed, false otherwise
*/
bool EraseAttributes(const std::string& pattern);


/**
* @brief getter for attribute
* @param name pointer to attribute name
Expand Down
16 changes: 16 additions & 0 deletions libs/xmltree/src/XmlItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ bool XmlItem::RemoveAttribute(const char* name)
return false;
}

bool XmlItem::EraseAttributes(const std::string& pattern)
{
set<string> attributesToErase;
for (const auto [key, _] : m_attributes) {

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs (macos-12, darwin, arm64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs (ubuntu-22.04, linux, arm64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs (ubuntu-22.04, linux, amd64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs (macos-12, darwin, amd64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / build (macos-12, darwin, amd64, .mac-amd64, https://developer.arm.com/-/media/Files/downloads/gnu...

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / build (macos-12, darwin, arm64, .mac-arm64, https://developer.arm.com/-/media/Files/downloads/gnu...

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / build (ubuntu-22.04, linux, amd64, .lin-amd64, https://developer.arm.com/-/media/Files/downloads/...

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / build (ubuntu-22.04, linux, arm64, .lin-arm64, https://developer.arm.com/-/media/Files/downloads/...

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / tests (ubuntu-22.04, linux, amd64, .lin-amd64, https://developer.arm.com/-/media/Files/downloads/...

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / tests (ubuntu-22.04, linux, arm64, .lin-arm64, https://developer.arm.com/-/media/Files/downloads/...

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / tests (macos-12, darwin, arm64, .mac-arm64, https://developer.arm.com/-/media/Files/downloads/gnu...

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / buildmgr / tests (macos-12, darwin, amd64, .mac-amd64, https://developer.arm.com/-/media/Files/downloads/gnu...

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / test (ubuntu-22.04, linux, amd64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / build (ubuntu-22.04, linux, amd64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / test (ubuntu-22.04, linux, arm64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / test (macos-12, darwin, amd64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / build (ubuntu-22.04, linux, arm64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / test (macos-12, darwin, arm64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / build (macos-12, darwin, amd64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packchk / build (macos-12, darwin, arm64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / build (ubuntu-22.04, linux, amd64, packgen, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / unittest (ubuntu-22.04, linux, amd64, packgen, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / build (ubuntu-22.04, linux, arm64, packgen, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / unittest (ubuntu-22.04, linux, arm64, packgen, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / unittest (macos-12, darwin, arm64, packgen, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / build (macos-12, darwin, arm64, packgen, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / build (macos-12, darwin, amd64, packgen, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / packgen / unittest (macos-12, darwin, amd64, packgen, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / build (ubuntu-22.04, linux, amd64, csolution, always, true, true)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / unittest (ubuntu-22.04, linux, arm64, csolution, always, false, false)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / build (ubuntu-22.04, linux, arm64, csolution, always, false, false)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / unittest (ubuntu-22.04, linux, amd64, csolution, always, true, true)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / unittest (macos-12, darwin, amd64, csolution, publicRepo, true, true)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / build (macos-12, darwin, arm64, csolution, publicRepo, false, false)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / unittest (macos-12, darwin, arm64, csolution, publicRepo, false, false)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / build (macos-12, darwin, amd64, csolution, publicRepo, true, true)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / build-swig (macos-12, darwin, amd64, csolution, publicRepo, true, true)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / projmgr / build-swig (ubuntu-22.04, linux, amd64, csolution, always, true, true)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / build (ubuntu-22.04, linux, amd64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / test (ubuntu-22.04, linux, arm64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / test (ubuntu-22.04, linux, amd64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / build (ubuntu-22.04, linux, arm64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / build (macos-12, darwin, amd64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / test (macos-12, darwin, arm64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / coverage

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / test (macos-12, darwin, amd64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / svdconv / build (macos-12, darwin, arm64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs / test_libs (ubuntu-22.04, linux, arm64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs / test_libs (macos-12, darwin, arm64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs / test_libs (ubuntu-22.04, linux, amd64, always)

loop variable ‘<structured bindings>’ creates a copy from type ‘const std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’ [-Wrange-loop-construct]

Check warning on line 128 in libs/xmltree/src/XmlItem.cpp

View workflow job for this annotation

GitHub Actions / test_libs / test_libs (macos-12, darwin, amd64, publicRepo)

loop variable '[key, _]' creates a copy from type 'const std::pair<const std::string, std::string>' [-Wrange-loop-construct]
if (WildCards::Match(pattern, key)) {
attributesToErase.insert(key);
}
}
if (attributesToErase.empty()) {
return false;
}
for (const auto& key : attributesToErase) {
RemoveAttribute(key);
}
return true;
}

const string& XmlItem::GetAttribute(const char* name) const
{
Expand Down
21 changes: 21 additions & 0 deletions libs/xmltree/test/src/XmlTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "gtest/gtest.h"

#include "XMLTree.h"
#include "RteUtils.h"

TEST(XmlTreeTest, GetAttribute) {

Expand Down Expand Up @@ -51,4 +52,24 @@ TEST(XmlTreeTest, GetAttribute) {
EXPECT_EQ(e.GetAttributeAsUnsigned("ten"), 10U);
EXPECT_EQ(e.GetAttributeAsUnsigned("zeroTen"), 8); // treated as octal
EXPECT_EQ(e.GetAttributeAsUnsigned("minusOne"), 0xFFFFFFFF);

// remove and erase
EXPECT_TRUE(e.HasValue("strVal"));
e.RemoveAttribute("string");
EXPECT_FALSE(e.HasValue("strVal"));
EXPECT_FALSE(e.HasAttribute("string"));

for (long i = 100; i < 103; i++) {
std::string val = RteUtils::LongToString(i);
std::string key = "attr_" + val;
e.SetAttribute(key.c_str(), i);
EXPECT_TRUE(e.HasValue(val));
}
EXPECT_TRUE(e.EraseAttributes("attr*"));
for (long i = 100; i < 103; i++) {
std::string val = RteUtils::LongToString(i);
EXPECT_FALSE(e.HasValue(val));
}
EXPECT_FALSE(e.EraseAttributes("attr*"));
}
// end of XmlTreeTest.cpp

0 comments on commit c14b5f1

Please sign in to comment.