gurkankaymak / hocon

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

(Yet another) comment issue #27

Open pgalbavy-itrs opened 2 years ago

pgalbavy-itrs commented 2 years ago

Again, thanks for the rapid fix for the previous issue, 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...

(I have confirmed that # /* this is an embedded comment */ also triggers an error)

Originally posted by @pgalbavy-itrs in https://github.com/gurkankaymak/hocon/issues/26#issuecomment-1307011861

josh-wolfe-okcupid commented 2 months ago

I took a look at solving this, and there's a pretty major problem where this package is using the golang tokenizer in the "test/scanner" package, and Go comments are skipped by default. This causes the bug in this issue by the "//\n" getting fully skipped and then the scanner looking for the end of the # comment consumes the following line too.

I have confirmed that this implementation of hocon incorrectly accepts /* ... */ style comments due to using the Golang tokenizer. I feel like fixing this would require fully replacing the scanner.Scanner with a custom tokenizer specifically for hocon, rather than trying to patch the Golang tokenizer. Given that this issue has been open nearly 2 years with no activity, I'm not inclined to do the work to contribute that major of an enhancement/redesign to this repo. i think it's gotta be the original maintainer that fixes this. I got this far before giving up.