Skip to content

🐛 fix(config): collapse continuation lines before factor filtering#3787

Merged
gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat:more
Feb 20, 2026
Merged

🐛 fix(config): collapse continuation lines before factor filtering#3787
gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat:more

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

When a factor-specific command uses backslash continuation (\) to span multiple lines, the continuation lines leak into environments that don't match the factor. For example with foo: python -c "\⏎ print('foo')", the print('foo')" line gets executed as a standalone command in the bar environment because expand_factors() sees it as an unfactored line.

🔧 The root cause is the ordering of operations in process_raw() — factor filtering via filter_for_env() splits by newlines and evaluates each line independently, but backslash continuation collapsing (\\\n removal) happened after filtering. Moving the continuation collapse to happen before factor filtering ensures multi-line commands are joined into a single line before the factor prefix check runs.

This is an INI-only issue since TOML configs don't use filter_for_env().

Fixes #2912

…ox-dev#2912)

Factor-specific multiline commands using backslash continuation no
longer leak continuation lines into non-matching environments.
@gaborbernat gaborbernat added bug:normal affects many people or has quite an impact area:configuration labels Feb 20, 2026
@gaborbernat gaborbernat enabled auto-merge (squash) February 20, 2026 04:03
@gaborbernat gaborbernat merged commit 78eb394 into tox-dev:main Feb 20, 2026
28 checks passed
@gaborbernat gaborbernat deleted the more branch February 20, 2026 04:41
gaborbernat added a commit that referenced this pull request Feb 20, 2026
Commit 78eb394 (#3787) moved continuation line collapsing (`\`) before
factor filtering to fix #2912, where factor-specific multiline commands
leaked continuation lines into non-matching environments. However, this
broke the common pattern of using different factor prefixes on
consecutive continuation lines — the collapsed single line caused
prefixes like `!cov:` to be passed as literal command arguments instead
of being filtered.

```ini
commands =
    cov: coverage run \
    !cov: python \
        somefile.py
```

Running `tox -e py-cov` produced `coverage run '!cov:' python
somefile.py` instead of `coverage run somefile.py`.

The fix restores the original order (factor filter first, collapse `\`
after) and makes `filter_for_env` continuation-aware. Two flags track
whether a kept line has an active backslash chain
(`active_continuation`) and whether a filtered-out line's continuation
should be skipped (`pending_skip`). An unfactored continuation line is
only dropped when it is exclusively reachable through removed factored
lines, preserving the fix for #2912 while restoring the conditional
continuation pattern from #3796.

Fixes #3796.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:configuration bot:chronographer:provided bug:normal affects many people or has quite an impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

factor-specific commands broken with multiline

1 participant