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

Make parsing of values syntactically more strict with bad values generating an error #244

Merged
merged 8 commits into from
Jun 4, 2020

Conversation

azeey
Copy link
Collaborator

@azeey azeey commented Apr 15, 2020

Currently, libsdformat silently ignores syntax errors when parsing values. For example, <pose>bad 0 0 0 0 0</pose> or <pose>0.1 0.2 0.3 0.4 0.5</pose> are both bad values for the <pose> tag, but the parsed values are <pose>0 0 0 0 0 0</pose> and <pose>0.1 0.2 0.3 0.4 0.5 0</pose> respectively. With this PR, libsdformat will generate an error for such values.

The plan is to make a similar PR for libsdformat9, but printing a warning message instead.

This resolves #228

@j-rivero
Copy link
Contributor

@osrf-jenkins run tests

src/Param.cc Outdated Show resolved Hide resolved
@scpeters
Copy link
Member

scpeters commented May 8, 2020

I think there are some test files missing that should start with bad_syntax_*


ss >> posetmp;
this->dataPtr->value = posetmp;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think the changes to this block are not needed because Param::SetFromString already calls sdf::trim to remove whitespace and then sets a default value if the trimmed string is empty. I've added tests to confirm this in 9daad39 of branch scpeters/stricter_parsing_10 after reverting the changes to this block in 8f6120c

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good. I see that ValueFromString is also called form the constructor without sdf::trim, but that should be okay because it's using the default string from the spec description.
https://github.com/osrf/sdformat/blob/b80e070dbed613e972acfb81e66b24a248eefd6c/src/Param.cc#L70

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just tried it and it looks like UNIT_Utils_TEST fails with that change.

Copy link
Member

Choose a reason for hiding this comment

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

ok, it sounds like this change is a good idea. Perhaps we could generalize it so it applies to types other than Pose?

Copy link
Member

Choose a reason for hiding this comment

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

I think we discussed this in our last meeting, and this was the last change we expected to make?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added an overload for sdf::trim that takes a std::string in fdecf77, and used that to trim input values in 32b3d84

@azeey
Copy link
Collaborator Author

azeey commented May 8, 2020

I think there are some test files missing that should start with bad_syntax_*

Oops! I've added them in 2b42034

@scpeters
Copy link
Member

scpeters commented May 8, 2020

there are test failures on macOS and windows; I've investigated the macOS failure, and it seems that the parsing the bad pose file doesn't generate an exception with the CI version of clang / libc++

@codecov-commenter
Copy link

codecov-commenter commented May 27, 2020

Codecov Report

Merging #244 into sdf10 will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            sdf10     #244      +/-   ##
==========================================
+ Coverage   86.64%   86.66%   +0.01%     
==========================================
  Files          59       59              
  Lines        9067     9071       +4     
==========================================
+ Hits         7856     7861       +5     
+ Misses       1211     1210       -1     
Impacted Files Coverage Δ
include/sdf/Types.hh 100.00% <ø> (ø)
src/Param.cc 92.15% <100.00%> (+0.09%) ⬆️
src/Types.cc 100.00% <100.00%> (ø)
src/parser.cc 77.52% <0.00%> (+0.11%) ⬆️

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 8bb2614...e59c6d7. Read the comment docs.

@scpeters
Copy link
Member

scpeters commented Jun 2, 2020

do you want to target this at sdf10?

azeey added 8 commits June 2, 2020 18:29
…rating an error

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
libc++ doesn't throw an exception on failbit, so check the bit by
calling `fail()`

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@azeey azeey changed the base branch from master to sdf10 June 2, 2020 23:29
@azeey
Copy link
Collaborator Author

azeey commented Jun 2, 2020

do you want to target this at sdf10?

Done.

@azeey azeey deleted the stricter_parsing_10 branch June 4, 2020 18:47
scpeters pushed a commit that referenced this pull request Jun 9, 2020
…rating an error (#244)

Currently, libsdformat silently ignores syntax errors when parsing values. For example, <pose>bad 0 0 0 0 0</pose> or <pose>0.1 0.2 0.3 0.4 0.5</pose> are both bad values for the <pose> tag, but the parsed values are <pose>0 0 0 0 0 0</pose> and <pose>0.1 0.2 0.3 0.4 0.5 0</pose> respectively. With this PR, libsdformat will generate an error for such values.
scpeters added a commit to scpeters/sdformat that referenced this pull request Jun 27, 2020
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
scpeters added a commit that referenced this pull request Jun 30, 2020
* Remove all deprecated *PoseFrame() APIs
* Remove deprecated Pose(), SetPose() APIs
* Migration guide: update per #244, #276
* Changelog for #308.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
scpeters added a commit to scpeters/sdformat that referenced this pull request Jun 30, 2020
…#308)

* Remove all deprecated *PoseFrame() APIs
* Remove deprecated Pose(), SetPose() APIs
* Migration guide: update per gazebosim#244, gazebosim#276
* Changelog for gazebosim#308.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
scpeters added a commit to scpeters/sdformat that referenced this pull request Jun 30, 2020
…#308)

* Remove all deprecated *PoseFrame() APIs
* Remove deprecated Pose(), SetPose() APIs
* Migration guide: update per gazebosim#244, gazebosim#276
* Changelog for gazebosim#308.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
scpeters added a commit that referenced this pull request Jul 2, 2020
* Remove all deprecated *PoseFrame() APIs
* Remove deprecated Pose(), SetPose() APIs
* Migration guide: update per #244, #276
* Changelog for #308.

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diagnostics for invalid numeric input
5 participants