I was testing YAML (yamljs) with random inputs (please don’t ask why it’s a long story :D). I’m not very well versed in the YAML spec, but as far as I understand YAML should be able to serialize and deserialize primitives (strings, numbers, booleans) without an object or array wrapper. This however doesn’t always seem to be the case.
I isolated one failing case:
import YAML from 'yamljs'
describe('YAML', () => {
it('should be equal to the input', () => {
const str = '0xn5t'
expect(YAML.parse(YAML.stringify(str))).toBe(str)
})
})
Where it '0xn5t'
is somehow parsed back to 5
Expected: "0xn5t"
Received: 5
Could someone please guide me to the spec where this behaviour is explained? Could this be an issue with the library I’m using?