Skip to content

Fix for custom element with attribute 'type'#811

Merged
scpeters merged 2 commits intochapulina/12/plugin_typefrom
aaron/plugin-type-fix
Dec 31, 2021
Merged

Fix for custom element with attribute 'type'#811
scpeters merged 2 commits intochapulina/12/plugin_typefrom
aaron/plugin-type-fix

Conversation

@aaronchongth
Copy link
Copy Markdown
Collaborator

Signed-off-by: Aaron Chong aaronchongth@gmail.com

🦟 Bug fix

Related to #809.

Summary

Reverted changes to parser for custom element with attribute 'type', added fix in ParamPrivate::ValueFromStringImpl instead.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

…added fix in ParamPrivate::ValueFromStringImpl instead

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 31, 2021

Codecov Report

❗ No coverage uploaded for pull request base (chapulina/12/plugin_type@5ee17ec). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                     Coverage Diff                     @@
##             chapulina/12/plugin_type     #811   +/-   ##
===========================================================
  Coverage                            ?   90.70%           
===========================================================
  Files                               ?       78           
  Lines                               ?    12432           
  Branches                            ?        0           
===========================================================
  Hits                                ?    11276           
  Misses                              ?     1156           
  Partials                            ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ee17ec...c630d30. Read the comment docs.

Copy link
Copy Markdown
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does look like a better fix; I just have one question about the order of some changes

Comment thread src/parser.cc Outdated
Comment on lines +1945 to +1955
if (elemXml->GetText() != nullptr)
{
const std::string attributeName(attribute->Name());
// TODO(chapulina) This isn't a good place to parse pose-specific
// attributes
if (elemName == "pose" && attributeName == "type")
typeName = attribute->Value();

element->AddAttribute(attributeName, "string", "", 1, "");
element->GetAttribute(attributeName)->SetFromString(
attribute->Value());
element->AddValue("string", elemXml->GetText(), true);
}

if (elemXml->GetText() != nullptr)
for (const tinyxml2::XMLAttribute *attribute = elemXml->FirstAttribute();
attribute; attribute = attribute->Next())
{
if (typeName.has_value())
element->AddValue(typeName.value(), elemXml->GetText(), true);
else
element->AddValue("string", elemXml->GetText(), true);
element->AddAttribute(attribute->Name(), "string", "", 1, "");
element->GetAttribute(attribute->Name())->SetFromString(
attribute->Value());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you've reversed the order of some logic in parser.cc, calling element->AddValue before / after setting the attribute values. Does this order matter? If not, can you reverse it so that the diff will be easier to read?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This order does not matter as in this case the value is always added as type string.

Only with specific types like pose, where the attributes like degrees or rotation_format are read, will it matter. But it still makes sense to have attributes handled before the value, regardless.

Reversed in c630d30.

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
Copy link
Copy Markdown
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@scpeters scpeters merged commit 27fc0a4 into chapulina/12/plugin_type Dec 31, 2021
@scpeters scpeters deleted the aaron/plugin-type-fix branch December 31, 2021 19:24
scpeters added a commit that referenced this pull request Jan 3, 2022
Signed-off-by: Louise Poubel <louise@openrobotics.org>

* Add line with unrecognized type

Signed-off-by: Steve Peters <scpeters@openrobotics.org>

* Fix for custom element with attribute 'type' (#811)

* Reverted changes to parser for custom element with attribute 'type',
  added fix in ParamPrivate::ValueFromStringImpl instead

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

Co-authored-by: Steve Peters <scpeters@openrobotics.org>
Co-authored-by: Aaron Chong <aaronchongth@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants