Skip to content

fix: Handle special characters in child names#20

Merged
erichlf merged 6 commits intohumblefrom
erich/fix_space_in_behavior_name_selector
Sep 9, 2025
Merged

fix: Handle special characters in child names#20
erichlf merged 6 commits intohumblefrom
erich/fix_space_in_behavior_name_selector

Conversation

@erichlf
Copy link
Collaborator

@erichlf erichlf commented Aug 27, 2025

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 SuccessOnSelected to 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

  • Handle special characters in SuccessOnSelected children.

Type of changes

  • New feature

Checklist

  • Update dependencies
  • Update version
  • Update README

Testing

  1. colcon build --packages-up-to py_trees_parser
  2. colcon test --event-handlers console_cohesion+ --packages-select py_trees_parser

Summary by CodeRabbit

  • Bug Fixes

    • SuccessOnSelected policy now correctly recognizes selected children whose names include special or non-ASCII characters.
  • Tests

    • Added test coverage and sample XML validating special-character node names in SuccessOnSelected and Parallel policies.
  • Chores

    • Bumped package version to 0.7.1, updated changelog, and added a test-time dependency for the test suite.
  • Documentation

    • Clarified using underscores to represent special or reserved characters in XML child names.

@erichlf erichlf self-assigned this Aug 27, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 27, 2025

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch erich/fix_space_in_behavior_name_selector

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 re

Optional: 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 = None

Optionally, 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.

📥 Commits

Reviewing files that changed from the base of the PR and between b23510f and 2136b86.

📒 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'.

@erichlf
Copy link
Collaborator Author

erichlf commented Aug 28, 2025

One major issue with this approach is that names are not unique, e.g. special! and special? have the same translation, i.e. special_.

@erichlf erichlf changed the title Erich/fix space in behavior name selector fix: Fix space in behavior name selector Aug 28, 2025
@erichlf erichlf changed the title fix: Fix space in behavior name selector fix: Handle special characters in child names Aug 28, 2025
@erichlf erichlf merged commit 0298cc0 into humble Sep 9, 2025
2 checks passed
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.

There are rumors of a bug with SuccessOnSelected

2 participants