Skip to content

fix: preserve # comment lines inside YAML block scalars in select_lines() - #1372

Closed
Jah-yee wants to merge 4 commits into
conda:mainfrom
Jah-yee:fix/select-lines-comment-preserve
Closed

Jah-yee wants to merge 4 commits into
conda:mainfrom
Jah-yee:fix/select-lines-comment-preserve

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Oct 8, 2026

Copy link
Copy Markdown

Fixes #1240

select_lines() was stripping comment-only lines from YAML block scalars.
Fix: track block scalar context to preserve # comments inside | or > blocks.

select_lines() was stripping all comment-only lines from YAML files,
but this incorrectly removed # comment lines that are part of
multi-line string values in block scalars (| or >).

For example, in:
  condarc: |
    # This config file should be located in ...
    allow_other_channels: yes

the # comment line was being stripped, breaking the string value.

Fix: track block scalar context by indentation level. When inside
a block scalar, preserve all lines verbatim (including # comments).
Exit block scalar context when we encounter a non-empty line at
the same or lower indentation level as the block key.

Fixes conda#1240
Tests verify:
- Lines that look like comments inside block scalars (| or >) are preserved
- After a block scalar ends, normal comment skipping resumes
- Both literal (|) and folded (>) block scalars handle # lines correctly

news/1371 documents the bug fix for block scalar comment handling.

Refs: conda#1371
Marcoesters suggested not filtering out comment-only lines since they
don't hurt anything. Removed the stripped.startswith('#') continue
filter so comments pass through to the selector match and are preserved.
@conda-bot

Copy link
Copy Markdown
Contributor

We require contributors to sign our Contributor License Agreement and we don't have one on file for @Jah-yee.

In order for us to review and merge your code, please e-sign the Contributor License Agreement PDF. We then need to manually verify your signature, merge the PR (conda/infrastructure#1481), and ping the bot to refresh the PR.

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

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

condarc key in construct.yaml improperly parses comments with '#'

2 participants