Skip to content

Commit

Permalink
Fix YAML.stringify() for certain null values (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 authored Sep 23, 2020
1 parent 9c8d758 commit ee431e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/doc/createNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createNode(value, tagName, ctx) {
let tagObj = findTagObject(value, tagName, tags)
if (!tagObj) {
if (typeof value.toJSON === 'function') value = value.toJSON()
if (typeof value !== 'object')
if (!value || typeof value !== 'object')
return wrapScalars ? new Scalar(value) : value
tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map
}
Expand Down
7 changes: 7 additions & 0 deletions tests/doc/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,10 @@ describe('YAML.stringify options as scalar', () => {
)
})
})

describe('YAML.stringify on ast Document', () => {
test('null document', () => {
const doc = YAML.parseDocument('null')
expect(YAML.stringify(doc)).toBe('null\n')
})
})

0 comments on commit ee431e2

Please sign in to comment.