havCSON v0.6.1 Released
Today I'm releasing version 0.6.1 of havCSON, only one day after version 0.6.0. While working on Exeligmos, I ran into a bug in the library, and looking into it turned up several more.
havCSON has two parsers and two writers: a plain pair for values, and a lossless pair that keeps comments and the order of members. The lossless writer puts an object inside an array in braces with one member per line, and the plain parser couldn't read that. It rejected the text or worse, read a member as part of the value above it without reporting an error. The fix for that is the first entry in the changelog below.
To be sure the fix was complete, I compared havCSON with the original CSON library for JavaScript. That turned up something I had never checked before: the original library couldn't read some of the text havCSON wrote or read a different value from it. A string with line breaks was written between triple quotes where CoffeeScript strips the indentation. A string containing #{ was taken for an interpolation and a key with a dash was rejected. A string with line breaks that ended with a double quote couldn't even be read back by havCSON itself.
Bugs like these end up in saved files, so I didn't want to leave them in a released version any longer than necessary. In my tests, the original library now reads everything havCSON writes and gets the same values. Files written by earlier versions are still read. Newly saved files can look different, though: a string with line breaks now sits on one line with \n escapes. Its value stays the same.
Reading isn't on par yet. The original library accepts some CSON that havCSON still rejects or reads differently, such as tabs for indentation and strings between triple quotes. I'll work on that next.
Changelog (v0.6.1)- Fixed parsing of objects in braces whose members are separated by line breaks, which the lossless writer produces. The plain parser rejected them or read a member as part of the value above it
- Fixed parsing of objects in braces and of arrays whose members or elements are separated by line breaks when a comment follows the opening brace or bracket
- Fixed lossless parsing of a member of an object in braces that is followed by a comma and an inline comment
- Fixed writing of strings with line breaks, which could not be read back when they ended with a double quote. They are now written on one line with escapes instead of between triple quotes
- Fixed writing of strings that contain "#{" and of keys that contain a dash, which other CSON tools could not read. Such strings are now written between single quotes, and such keys between quotes
- Fixed ToJsonString writing control characters as they are instead of as escapes