dominictarr / rc

The non-configurable configuration loader for lazy people.
Other
1.02k stars 97 forks source link

problem parsing valid JSON array #80

Open electerious opened 8 years ago

electerious commented 8 years ago

My .rc file contains a valid JSON starting with a square bracket:

[
  { "hello": "world" }
]

And rc outputs the following:

{ '[': true,
  '{ "hello": "world" }': true,
  ']': true,
  _: [],
  configs: [ '/Users/tobiasreich/Sites/Rosid/.rosidrc' ],
  config: '/Users/tobiasreich/Sites/Rosid/.rosidrc' }

I tested the strip-json-comments module and it's not causing this problem. I guess it's because rc tries to merge the JSON with the defaults.

legodude17 commented 8 years ago

The problem is caused by the auto detection of ini. The parser parses anything that starts with { as JSON and anything else as ini. My PR (#85) will actually fix that.

dominictarr commented 8 years ago

it doesn't make sense to use a array inside an rc config file. this should be treated as an error.

legodude17 commented 8 years ago

Even if you think of that as an error, parsing it as ini is definitely the wrong response. Maybe you could just error if the first char is [ and it is on its own line?