Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/dayamlchecker/yaml_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,9 @@ def find_errors_from_string(
runtime_options: Optional[RuntimeOptions] = None,
) -> list[YAMLError]:
"""Preprocess opted-in Jinja templates, then run normal YAML validation."""
# Match the universal newlines that find_errors() gets from open(): a "---\r"
# separator would otherwise not split, collapsing the file into one block.
full_content = full_content.replace("\r\n", "\n").replace("\r", "\n")
partial_findings: list[YAMLError] = []
if uses_jinja(full_content):
from dayamlchecker._jinja import render_yaml
Expand Down
16 changes: 16 additions & 0 deletions tests/test_yaml_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3213,6 +3213,22 @@ def test_null_mako_value_is_reported_not_raised(self):
f"A null value has no Mako to report on, got: {errs}",
)

def test_crlf_document_separators_split_blocks(self):
# Callers like the Weaver pass raw strings, so CRLF is not normalized
# by open(); "---\r" must still separate blocks.
source = (
"include:\r\n - shared.yml\r\n---\r\n"
"metadata:\r\n title: Test\r\n---\r\n"
"code: |\r\n broken =\r\n"
)
errs = find_errors_from_string(source, input_file="<string_crlf>")
self.assertFalse(_has_code(errs, "EG102"), f"Unexpected parse error: {errs}")
self.assertTrue(_has_code(errs, "EG122"), f"Expected a syntax error: {errs}")
lf_errs = find_errors_from_string(
source.replace("\r\n", "\n"), input_file="<string_crlf>"
)
self.assertEqual(errs, lf_errs)


if __name__ == "__main__":
unittest.main()
Loading