Skip to content

fix: strip whitespace from YAML string before parsing#88

Open
opoudjis wants to merge 1 commit into
mainfrom
fix/yaml-strip-before-parse
Open

fix: strip whitespace from YAML string before parsing#88
opoudjis wants to merge 1 commit into
mainfrom
fix/yaml-strip-before-parse

Conversation

@opoudjis

Copy link
Copy Markdown
Contributor

Summary

  • FormatDetector.detect_string_uncached applies str.strip before checking trimmed.start_with?("---"), but YamlComparator.parse_yaml passes the raw unstripped string to YAML.safe_load. This means a string can be auto-detected as valid YAML but then fail to parse with Psych::SyntaxError.
  • This is especially relevant for the be_equivalent_to matcher (new in 0.2.0) which auto-detects format and commonly receives heredoc strings with leading/trailing whitespace.
  • Adds .strip to parse_yaml to match the detector behavior, plus tests for the whitespace scenarios.

Test plan

  • Added 3 new tests in yaml_comparator_spec.rb covering leading whitespace before ---, trailing whitespace, and heredoc-style inconsistent indentation
  • All 28 YAML comparator tests pass
  • Verified fix resolves the downstream failure in metanorma/metanorma

FormatDetector.detect_string_uncached applies str.strip before checking
trimmed.start_with?("---"), but YamlComparator.parse_yaml passes the raw
unstripped string to YAML.safe_load. This inconsistency means a string
can be auto-detected as valid YAML but then fail to parse — e.g. a
heredoc with leading whitespace before "---".

This is especially relevant for the new be_equivalent_to matcher
(introduced in 0.2.0) which auto-detects format and commonly receives
heredoc strings with leading/trailing whitespace.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants