zemirco / json2csv-stream

Transform stream from json to csv
52 stars 17 forks source link

Parsing breaks when curly brace used inside text (regex) #7

Closed g2010a closed 7 years ago

g2010a commented 9 years ago

The regular expression used to identify objects in the _transform function cannot cope with curly braces embedded in text.

E.g. if the input file is [{"id":2089,"name":"[somename]{ep}: somethingelse","statusid":"o","something":false}]

Then the following error will be raised: crit: uncaughtException SyntaxError: Unexpected end of input

A possible fix is to use the following regular expression instead of what is being used now (index.js:77):

  // regular expression looking for json in chunk
  var re = /(?!\s|\}|$)\{[^\}"]*("(\\.|[^\\"])*"[^\}"]*)*\}/g;
knownasilya commented 9 years ago

@g2010a think you could submit a PR making the change?

samuelwu90 commented 8 years ago

@knownasilya - looks like the fix has been merged. Would you mind publishing a new version to npm with the fix? 😄

montumodi commented 7 years ago

@knownasilya Can you please publish the new version to npm with fix? We are facing a production issue because of this and need this urgently.

knownasilya commented 7 years ago

Published, thanks for the ping.