Skip to content

Commit

Permalink
fix: Do not allow tab before block collection (fixes #549)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Jun 8, 2024
1 parent 99fc94d commit 1d902e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/compose/resolve-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function resolveProps(
if (
!flow &&
atNewline &&
indicator !== 'doc-start' &&
(indicator !== 'doc-start' || next?.type !== 'flow-collection') &&
token.source[0] === '\t'
) {
tab = token
Expand Down
23 changes: 16 additions & 7 deletions tests/doc/errors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import * as YAML from 'yaml'
import { source } from '../_utils'

test('fail on map value indented with tab', () => {
const src = 'a:\n\t1\nb:\n\t2\n'
const doc = YAML.parseDocument(src)
expect(doc.errors).not.toHaveLength(0)
expect(() => String(doc)).toThrow(
'Document with errors cannot be stringified'
)
describe('tabs as indentation', () => {
test('fail on map value indented with tab', () => {
const src = 'a:\n\t1\nb:\n\t2\n'
const doc = YAML.parseDocument(src)
expect(doc.errors[0]).toMatchObject({ code: 'TAB_AS_INDENT' })
})

test('block sequence with leading tab', () => {
const doc = YAML.parseDocument('\t- x')
expect(doc.errors).toMatchObject([{ code: 'TAB_AS_INDENT' }])
})

test('block map with leading tab', () => {
const doc = YAML.parseDocument('\tx: y')
expect(doc.errors).toMatchObject([{ code: 'TAB_AS_INDENT' }])
})
})

test('eemeli/yaml#6', () => {
Expand Down

0 comments on commit 1d902e9

Please sign in to comment.