Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty strings in plugin and custom attributes #1407

Merged
merged 4 commits into from
May 20, 2024

Conversation

scpeters
Copy link
Member

🦟 Bug fix

Fixes #725

Summary

Currently errors are generated when adding an attribute containing an empty string to a <plugin> block or as a custom attribute. This adds failing tests in 0637c21 to confirm the bug and fixes the errors in e55a9e1 by setting _required == 0 when calling Element::AddAttribute.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • 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.

This demonstrates the bug reported in #725.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
This allows custom attributes and unrecognized
attributes to contain empty strings by setting
required == 0 when calling Element::AddAttribute.

Fixes #725.

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

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Looks good, but can you check the output of ToString() to make sure the custom attribute is included? I seem to recall that was a problem.

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.44%. Comparing base (ff9b3ad) to head (e55a9e1).
Report is 13 commits behind head on sdf14.

Current head e55a9e1 differs from pull request most recent head 39036ee

Please upload reports for the commit 39036ee to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##            sdf14    #1407      +/-   ##
==========================================
+ Coverage   92.42%   92.44%   +0.01%     
==========================================
  Files         134      135       +1     
  Lines       17751    17837      +86     
==========================================
+ Hits        16406    16489      +83     
- Misses       1345     1348       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member Author

scpeters commented May 1, 2024

Looks good, but can you check the output of ToString() to make sure the custom attribute is included? I seem to recall that was a problem.

ok, thanks for bringing that up. I updated ElementPrivate::PrintAttributes in a4f811f to always print custom attributes

Empty attributes in the <plugin/> element won't be printed by ToString unless they are in a custom xml namespace, as I've noticed with the following test patch:

diff --git a/test/integration/plugin_attribute.cc b/test/integration/plugin_attribute.cc
index 7f4f9f4c..b66c9da1 100644
--- a/test/integration/plugin_attribute.cc
+++ b/test/integration/plugin_attribute.cc
@@ -65,4 +65,9 @@ TEST(PluginAttribute, ParseAttributes)
     EXPECT_EQ(value->Get<std::string>(""),
               std::string("value"));
   }
+  {
+    auto pluginToString = plugin->ToString("");
+    EXPECT_NE(std::string::npos, pluginToString.find("empty_attribute=''"))
+      << pluginToString;
+  }
 }

I don't have a good idea for how to fix it, so I'd prefer to open an issue documenting that behavior and potentially close it as won't fix

Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

LGTM! Opening an issue to document the behavior in <plugin> sounds good.

@scpeters
Copy link
Member Author

LGTM! Opening an issue to document the behavior in <plugin> sounds good.

opened a new issue: #1421

@scpeters scpeters enabled auto-merge (squash) May 20, 2024 20:57
@scpeters scpeters merged commit c9779cb into sdf14 May 20, 2024
13 checks passed
@scpeters scpeters deleted the scpeters/allow_empty_custom_attributes branch May 20, 2024 21:00
aagrawal05 pushed a commit to aagrawal05/sdformat that referenced this pull request Aug 16, 2024
Currently errors are generated when adding an attribute
containing an empty string to a <plugin> block or as a
custom attribute. This adds failing tests to confirm the bug
and fixes the errors in by setting `_required == 0` when
calling Element::AddAttribute. This also changes
Element::ToString to print empty custom attributes.

Fixes gazebosim#725.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
aagrawal05 pushed a commit to aagrawal05/sdformat that referenced this pull request Aug 16, 2024
Currently errors are generated when adding an attribute
containing an empty string to a <plugin> block or as a
custom attribute. This adds failing tests to confirm the bug
and fixes the errors in by setting `_required == 0` when
calling Element::AddAttribute. This also changes
Element::ToString to print empty custom attributes.

Fixes gazebosim#725.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Error when attributes in custom elements have empty values
2 participants