safeLoad(): Make options optional #61

Closed
mk-pmb opened this Issue Feb 9, 2013 · 3 comments

Comments

Projects
None yet
4 participants

mk-pmb commented Feb 9, 2013

When calling YAML.safeLoad(content) without a second argument (options), I get this error:

/foobar/node_modules/js-yaml/lib/js-yaml/common.js:50
  var index, length, key, sourceKeys = Object.keys(source);
                                              ^
TypeError: Object.keys called on non-object
    at Function.keys (native)

Passing an empty object literal ({}) fixes the problem but looks out of place.

$ npm ls js-yaml
/foobar
+-- js-yaml@2.0.0

dervus closed this in fcb2d2e Feb 9, 2013

Collaborator

dervus commented Feb 9, 2013

Fixed. Thanks!

Owner

puzrin commented Feb 9, 2013

published 2.0.1 with fix. please, check that it's ok.

In the README example code, a second argument is passed to safeLoad which is a string and not an object:

// Get document, or throw exception on error
try {
  var doc = yaml.safeLoad(fs.readFileSync('/home/ixti/example.yml', 'utf8'));
  console.log(doc);
} catch (e) {
  console.log(e);
}

That code gives me the same error [TypeError: Object.keys called on non-object].
But when I remove , 'utf8', it's all good. Why is that happening?

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