diff --git a/src/dayamlchecker/yaml_structure.py b/src/dayamlchecker/yaml_structure.py index ddd656d..d1bc471 100644 --- a/src/dayamlchecker/yaml_structure.py +++ b/src/dayamlchecker/yaml_structure.py @@ -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 diff --git a/tests/test_yaml_structure.py b/tests/test_yaml_structure.py index 570d168..5e4697e 100644 --- a/tests/test_yaml_structure.py +++ b/tests/test_yaml_structure.py @@ -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="") + 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="" + ) + self.assertEqual(errs, lf_errs) + if __name__ == "__main__": unittest.main()