gazebosim / gazebosim/sdformat
`sdf::Element::Copy` should clear existing attributes of the destination element
- Dominant language
- C++
- Stars
- 216
- Forks
- 125
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 14
Description
## Environment
* OS Version: any
* Source or binary build? any
## Description
* Expected behavior: After using `sdf::Element::Copy`, the source and destination elements should have the same attributes.
* Actual behavior: Existing attributes of the destination `sdf::Element` are not removed. This results in the destination `sdf::Element` having a different set of attributes that have been set than the source. https://github.com/osrf/sdformat/blob/689ee8410a97917e2087ffd5045861d63258ebd4/src/Element.cc#L217-L227
## Steps to reproduce
This snippet of code demonstrates the issue
```c++
sdf::ElementPtr src = std::make_shared();
sdf::ElementPtr dest = std::make_shared();
src->AddAttribute("foo", "int", "0", false, "foo description");
src->GetAttribute("foo")->Set(1);
dest->AddAttribute("bar", "int", "0", false, "foo description");
dest->GetAttribute("bar")->Set(2);
dest->Copy(src);
EXPECT_FALSE(src->HasAttribute("bar"));
// This expectation should succeed because `src` doesn't have the `bar`
// attribute and we expect `dest` to not have it as well because its a copy of
// `src`. However, currently, it fails because `dest` still has the `bar`
// attribute.
EXPECT_FALSE(dest->HasAttribute("bar"));
```
Contributor guide
Research direction
Start in src/Element.cc at the sdf::Element::Copy implementation linked in the issue, then reproduce the case with source attribute foo and destination attribute bar. Verify that copying leaves the destination with the same attributes as the source, including removing attributes absent from the source.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100