Skip to content

fix(yaml): reject tab characters used as block indentation - #7366

Open
Harsh23Kashyap wants to merge 1 commit into
denoland:mainfrom
Harsh23Kashyap:fix/yaml-reject-tab-indentation
Open

Harsh23Kashyap wants to merge 1 commit into
denoland:mainfrom
Harsh23Kashyap:fix/yaml-reject-tab-indentation

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown

Closes #7359

parse() skips a tab at the start of a line like any other whitespace, so the line is read at the wrong depth. parse("a:\n\tb: 1") returns { a: null, b: 1 } instead of throwing.

This records when a tab shows up before any content on a line, and throws a YamlSyntaxError if that line starts a block mapping or sequence entry. Tabs after a colon or dash, in comments, and on blank lines still parse as before.

Before, on main:

"a:\n\tb: 1"       -> {"a":null,"b":1}
"a:\n  b:\n\tc: 2" -> {"a":{"b":null},"c":2}
"a:\n \tb: 1"      -> {"a":{"b":1}}

After:

"a:\n\tb: 1"       THROWS Tab characters must not be used in indentation at line 2, column 2
"a:\n  b:\n\tc: 2" THROWS Tab characters must not be used in indentation at line 3, column 2
"a:\n \tb: 1"      THROWS Tab characters must not be used in indentation at line 2, column 3

js-yaml and the yaml npm package reject the same three inputs. One correction to the issue: "- a\n-\tb" is accepted by both of them, because the tab there separates the dash from the value, so I left that case alone and added a test that it still parses.

deno test yaml/ front_matter/ passes, and the new test fails without the change. deno fmt, deno lint and deno check are clean for yaml/.

parse() accepted a tab at the start of a line as indentation. The tab was
skipped like any other whitespace, so the line was read at the wrong
depth: parse("a:\n\tb: 1") returned { a: null, b: 1 }.

Record when a tab appears before any content on a line and throw a
YamlSyntaxError if that line starts a block mapping entry or sequence
entry. Tabs used as separation (after a colon or a dash), in comments and
on blank lines are still accepted.

Closes denoland#7359
@github-actions github-actions Bot added the yaml label Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.04%. Comparing base (f834d02) to head (b19e862).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7366    +/-   ##
========================================
  Coverage   95.04%   95.04%            
========================================
  Files         619      618     -1     
  Lines       52012    51773   -239     
  Branches     9450     9407    -43     
========================================
- Hits        49434    49209   -225     
+ Misses       2031     2022     -9     
+ Partials      547      542     -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@std/yaml parse silently misparses documents with tab indentation instead of rejecting them

1 participant