Skip to content

Ignore non-template shell env entries during template matching #3

Description

@rsgalloway

pathbase parse can crash while scanning environment-backed templates if the process environment includes shell function exports or other non-template values that happen to contain ${...} and path-like text.

Observed behavior:
A shell-exported value such as BASH_FUNC_module%% was treated as a candidate template, which led to regex compilation failing with re.error: bad character in group name ... during match_template() / find_matching_templates().

Expected behavior:

  • Only real pathbase templates should be considered during environment template matching. Invalid or unrelated env entries should be skipped without crashing the CLI.

Root cause:

  • Template candidate detection was too permissive, and regex compilation errors were not normalized into InvalidTemplateError, so malformed env-derived template strings could escape as uncaught re.error.

Fix:

  • Tighten env template detection to require actual Python format fields.
  • Treat regex compilation failures as invalid templates and skip them.
  • Add a regression test covering shell-function-style env pollution.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions