gurkankaymak / hocon

go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config
MIT License
79 stars 17 forks source link

Another comment oddity #26

Closed pgalbavy-itrs closed 2 years ago

pgalbavy-itrs commented 2 years ago

Thanks for the rapid fix of #25

I am trying to support in-the-field config files, so I have to test against messy files.

In this case:

"key": {
    "name": value
    # comment on it's own line - this is OK
    "name2": value
    # comment on it's own line - remove this and it works
    "name3": {
        "another": value
    }
}

generates:

$ ./play 
panic: invalid config object! at: 9:1, invalid token }

goroutine 1 [running]:
main.main()
        /home/peter/play/main.go:39 +0x7e5

removing the second comment - when it precedes a { ... } fixes it.

gurkankaymak commented 2 years ago

thanks for reporting, the problem was with the ' character, if a line contains it the golang parser appends newline (\n) to the latest token instead of a separate token, in that case the next line is also consumed as comment

pgalbavy-itrs commented 2 years ago

Again, thanks for the rapid fix, but found yet another one. I can share our full default config file if it helps?

key: {
    # //
    name: {
        name: value
    }
}

Any URL in a comment before a { ... } encodes object causes an error - I will assume it's the '//' being seen as a comment as well and getting something out of sync. I have not checked what happens for / ... / inside # or // prefixed single lines, but I am guessing it's going to have similar issues...

pgalbavy-itrs commented 2 years ago

Yep, this also fails:

key: {
    # /* this is not ok */
    name: {
        name: value
    }
}