js-fuzz icon indicating copy to clipboard operation
js-fuzz copied to clipboard

error running example. TypeError: content.getContent is not a function

Open cdetrio opened this issue 8 years ago • 1 comments

When I try to run the example:

$ bin/js-fuzz ../fuzz.js

TypeError: content.getContent is not a function
    at Log.List.add.List.addItem.List.appendItem (/Users/macbook/dev_fuzz/js-fuzz/node_modules/blessed/lib/widgets/list.js:297:61)
    at Log.List.setItems (/Users/macbook/dev_fuzz/js-fuzz/node_modules/blessed/lib/widgets/list.js:384:12)
    at Log.log (/Users/macbook/dev_fuzz/js-fuzz/node_modules/blessed-contrib/lib/widget/log.js:26:8)
    at Stats.<anonymous> (/Users/macbook/dev_fuzz/js-fuzz/lib/src/Stats.js:203:66)
    at emitOne (events.js:96:13)
    at Stats.emit (events.js:191:7)
    at Stats.log (/Users/macbook/dev_fuzz/js-fuzz/lib/src/Stats.js:76:14)
    at Cluster.<anonymous> (/Users/macbook/dev_fuzz/js-fuzz/lib/src/Cluster.js:149:67)
    at emitOne (events.js:96:13)
    at Cluster.emit (events.js:191:7)

It appears related to this line and the blessed dependency.

cdetrio avatar Jun 28 '17 11:06 cdetrio

I assume this is about a parser error in the example. Try the following instead:

const JSON5 = require('json5')

exports.fuzz = input => {
  input = input.toString('utf8') // we give you buffers by default

  let isPlainJSON = true
  let isJSON5 = true
  try { JSON.parse(input) } catch (e) { isPlainJSON = false }
  try { JSON5.parse(input) } catch (e) { isJSON5 = false }

  // We catch and thrown errors and mark them as failures
  if (isPlainJSON && !isJSON5) {
    throw new Error('Found a string that was JSON but not JSON5');
  }

  return isPlainJSON ? 1 : 0
}

adrianheine avatar Nov 03 '17 23:11 adrianheine