Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions spec/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,9 @@ def split_jobs(text):
# A `key: |`/`key: >` block-scalar indicator, with an optional anchor (`&name`) before it.
# Anchored whole-line so `key: "a|b"` does not match.
_BLOCK_SCALAR_KEY = re.compile(r"^[^:#\n]*:\s*(&\S+\s+)?[|>][0-9+-]*\s*(#.*)?$")
# A step's `- key: |` sequence-item prefix, stripped before matching the key pattern above.
# A bare `- |`/`- >` sequence item, a block scalar with no mapping key at all (a matrix string).
_BARE_BLOCK_SCALAR = re.compile(r"^(&\S+\s+)?[|>][0-9+-]*\s*(#.*)?$")
# A step's `- key: |` sequence-item prefix, stripped before matching the two patterns above.
_SEQUENCE_ITEM_PREFIX = re.compile(r"^-[ \t]+")


Expand All @@ -1495,15 +1497,19 @@ def _code_view(text):
else:
continue # still inside the block scalar body, not real structure
stripped = ln.lstrip()
key_col = len(ln) - len(stripped)
dash_col = len(ln) - len(stripped)
key_col = dash_col
dash = _SEQUENCE_ITEM_PREFIX.match(stripped)
if dash:
# The out-indent boundary is the key's own column, not the dash's.
# A keyed scalar's boundary is the key's own column, not the dash's.
# A sibling key genuinely at that column (`env:` alongside a `- run: |` step) is real structure.
key_col += dash.end()
stripped = stripped[dash.end() :]
if _BLOCK_SCALAR_KEY.match(stripped):
skip_indent = key_col
elif dash and _BARE_BLOCK_SCALAR.match(stripped):
# A bare `- |` has no key, so its own boundary is the dash's column, not a key past it.
skip_indent = dash_col
out.append(ln)
return "\n".join(out)

Expand Down Expand Up @@ -2963,6 +2969,12 @@ def _selftest():
" deploy:\n name: &lbl |\n with:\n environment:\n",
" deploy:\n name: &lbl |",
),
(
# A bare sequence item (a matrix string) has no key, so its boundary is the dash's column.
"a bare sequence-item block scalar (`- |`, a matrix string) still drops its body",
" include:\n - |\n TOKEN\n",
" include:\n - |",
),
]
for label, text, want in code_view_cases:
got = _code_view(text)
Expand Down
Loading