Older safe* functions were renamed.
js-yaml v3:
yaml.safeLoad(str)
yaml.safeLoadAll(str)
yaml.safeDump(obj)js-yaml v4:
yaml.load(str)
yaml.loadAll(str)
yaml.dump(obj)!!js/function, !!js/regexp, !!js/undefined type definitions are moved to external package js-yaml-js-types. To restore previous (unsafe) behaviour, use a custom extended schema.
js-yaml v3:
yaml.load(str)
yaml.loadAll(str)
yaml.dump(obj)js-yaml v4:
let schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all)
yaml.load(str, { schema })
yaml.loadAll(str, { schema })
yaml.dump(obj, { schema })js-yaml v3:
let schema1 = yaml.DEFAULT_SAFE_SCHEMA
let schema2 = yaml.DEFAULT_FULL_SCHEMA
let schema3 = yaml.Schema.create(yaml.DEFAULT_SAFE_SCHEMA, [ customTags ])js-yaml v4:
let schema1 = yaml.DEFAULT_SCHEMA
let schema2 = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all)
let schema3 = yaml.DEFAULT_SCHEMA.extend([ customTags ])js-yaml v3 may dump some strings starting with 0 without quotes. They will load as numbers in v4.
Affected data (if you have these unquoted strings, they may get converted to numbers):
- integers starting with
0that contain8or9digits"0128"dumped by v3 as0128then parsed by v4 into number128"0127"is not affected, because it's dumped by v3 as"0127"(it looks like old-style octal, so v3 quotes it)
- floats starting with
0(except for0.)"012.34"dumped by v3 as012.34then parsed by v4 into number12.34"012e+4"dumped by v3 as012e+4then parsed by v4 into number120000"0.0123"is not affected (it looks like a normal float, so v3 quotes it)
This is what happens:
let data = '0123456789'
// typeof data === 'string'
str = require('js-yaml@3').dump('0123456789')
data = require('js-yaml@4').load(str)
// data will be 123456789
// typeof data === 'number'You can check for these patterns in your data using regexp like this:
grep '\(^\|:\s\s*\)0[0-9][.0-9]*\s*$' *.ymlIf you have these in your yaml files anywhere, you should quote them (e.g. 0123456789 => "0123456789").
If you reference anything inside js-yaml/lib folder, i.e. require('js-yaml/lib/XXX'), you'll need to change paths.
js-yaml v3:
require('js-yaml/lib/js-yaml/common');
require('js-yaml/lib/js-yaml/type/int');js-yaml v4:
require('js-yaml/lib/common');
require('js-yaml/lib/type/int');