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
Closed
yousefmasarwa97 wants to merge 2 commits into
yousefmasarwa97 wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #5520.
ProjectConfigBase._expand_interpolationsrewrites the legacy brace-less$PROJECT_HASHinto${PROJECT_HASH}before interpolation. The guard that skips an escaped occurrence ($$PROJECT_HASH) readvalue[x - 1]. When the variable is at the start of the value,xis0, sovalue[-1]inspected the last character of the string instead of a (non-existent) preceding one. A value that both starts with$PROJECT_HASHand 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 withx > 0.tests/project/test_config.py: add a regression test (test_legacy_variable_at_value_start).HISTORY.rst: changelog entry.Testing
tests/project/test_config.pypass with no regressions.black --check,isort --check-only, andpylint(errors) report clean on the changed files.Investigated with AI assistance; I reviewed the change, reproduced it, and tested it locally.