fix: Handle special characters in child names#20
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
py_trees_parser/parser.py (2)
505-510: Sanitization: switch to regex and precompute set for clarity and speed.Regex keeps intent clear, preserves underscores, and set lookup avoids repeated list scans.
Apply within this hunk:
- selection = [ - child - for child in children - if "".join(map(lambda char: char if char.isalnum() else "_", child.name)) - in on_selected - ] + on_selected_set = set(on_selected) + selection = [ + child + for child in children + if re.sub(r"\W", "_", child.name) in on_selected_set + ]Also add once near the other imports:
import reOptional: warn on collisions/unmatched selections (two children mapping to same sanitized key or keys not found).
165-201: Avoid UnboundLocalError when 'children' arg is missing/malformed.children_arg may be referenced before assignment if SuccessOnSelected lacks a children list; initialize and fail gracefully.
Minimal patch:
on_selected = None synchronise = None + children_arg = NoneOptionally, after computing on_selected, validate all requested names were matched and log/warn about any unmatched entries.
test/data/test_on_selected.xml (1)
1-13: Good fixture; consider adding a collision case.Add a second child whose sanitized name collides (e.g., "¢@mera-va!ue,_check?") and assert both are selected to document current semantics or to enforce a uniqueness check.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
package.xml(1 hunks)py_trees_parser/parser.py(1 hunks)test/data/test_on_selected.xml(1 hunks)test/test_parser.py(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: .github/workflows/testing.yml
test/test_parser.py
[error] 227-227: D103 Missing docstring in public function 'test_SuccessOnSelected_speacial_chars_in_name'.
|
One major issue with this approach is that names are not unique, e.g. special! and special? have the same translation, i.e. special_. |
This PR aims to fix issues where special characters exist in a behavior name that is referenced by
SuccessOnSelected.Fixes #18
Motivation and Context
The list of children in
SuccessOnSelectedto select is expected to be a list of python variables, thus they cannot have special characters. To deal with this limitation, we replace the special character with an underscore, i.e._.Changes
SuccessOnSelectedchildren.Type of changes
Checklist
Testing
colcon build --packages-up-to py_trees_parsercolcon test --event-handlers console_cohesion+ --packages-select py_trees_parserSummary by CodeRabbit
Bug Fixes
Tests
Chores
Documentation