Skip to content

Fix legacy PROJECT_HASH at start of value not expanded when value ends with a dollar sign - #5521

Closed
yousefmasarwa97 wants to merge 2 commits into
platformio:developfrom
yousefmasarwa97:fix/legacy-var-at-value-start
Closed

yousefmasarwa97 wants to merge 2 commits into
platformio:developfrom
yousefmasarwa97:fix/legacy-var-at-value-start

Conversation

@yousefmasarwa97

Copy link
Copy Markdown

Description

Fixes #5520.

ProjectConfigBase._expand_interpolations rewrites the legacy brace-less $PROJECT_HASH into ${PROJECT_HASH} before interpolation. The guard that skips an escaped occurrence ($$PROJECT_HASH) read value[x - 1]. When the variable is at the start of the value, x is 0, so value[-1] inspected the last character of the string instead of a (non-existent) preceding one. A value that both starts with $PROJECT_HASH and ends with $ (e.g. $PROJECT_HASH-$) was therefore treated as escaped and left unexpanded.

The fix only skips when there is a real preceding character (x > 0). Mid-string variables, escaped $$ occurrences, and non-matches are unaffected.

Changes

  • platformio/project/config.py: guard the escaped-variable check with x > 0.
  • tests/project/test_config.py: add a regression test (test_legacy_variable_at_value_start).
  • HISTORY.rst: changelog entry.

Testing

  • The new test fails against the current code and passes with the fix.
  • Interpolation tests in tests/project/test_config.py pass with no regressions.
  • black --check, isort --check-only, and pylint (errors) report clean on the changed files.

Investigated with AI assistance; I reviewed the change, reproduced it, and tested it locally.

ProjectConfigBase._expand_interpolations rewrites the brace-less legacy
variable `\` into `\` before interpolation.
The guard that skips an escaped occurrence (`\$\`) read
`value[x - 1]`; when the variable is at the start of the value `x` is 0,
so `value[-1]` inspected the last character instead of a preceding one. A
value that both starts with `\` and ends with `\$` (e.g.
`\-\$`) was therefore treated as escaped and left unexpanded.

Only skip when there is a real preceding character (`x > 0`). Mid-string
variables, escaped `\$\$` occurrences, and non-matches are unaffected.
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.

Legacy PROJECT_HASH at start of value not expanded when value ends with a dollar sign

2 participants