Skip to content

Skip shell env noise when matching pathbase templates - #4

Merged
rsgalloway merged 4 commits into
masterfrom
fix/env-template-matching
Aug 12, 2026
Merged

Skip shell env noise when matching pathbase templates#4
rsgalloway merged 4 commits into
masterfrom
fix/env-template-matching

Conversation

@rsgalloway

Copy link
Copy Markdown
Owner

This pull request improves the robustness of template detection and error handling in the pathbase template logic. The main changes focus on ensuring that only valid path templates are considered, and that errors in template pattern compilation are handled gracefully. Additionally, a new test ensures that shell environment variables that do not represent file paths are ignored.

Template detection and validation:

  • Updated _iter_template_items in lib/pathbase/template.py to use string.Formatter().parse() for validating template strings, ensuring only strings with valid template fields are considered, and added logic to skip invalid or non-template values. [1] [2]
  • Added a test (test_find_matching_templates_ignores_shell_env_values) in tests/test_template.py to verify that shell environment variables (such as BASH_FUNC_module%%) are ignored when searching for matching templates.

Error handling improvements:

  • Wrapped the call to _compile_pattern() in the Template class constructor with a try/except block to catch and re-raise regular expression errors as InvalidTemplateError, improving error reporting for invalid templates.

@rsgalloway rsgalloway self-assigned this Aug 12, 2026
@rsgalloway rsgalloway added the bug Something isn't working label Aug 12, 2026
@rsgalloway rsgalloway linked an issue Aug 12, 2026 that may be closed by this pull request
@rsgalloway
rsgalloway requested a lite review from Copilot August 12, 2026 13:21
@rsgalloway
rsgalloway merged commit a4620da into master Aug 12, 2026
14 checks passed
@rsgalloway
rsgalloway deleted the fix/env-template-matching branch August 12, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore non-template shell env entries during template matching

1 participant