dotenvy icon indicating copy to clipboard operation
dotenvy copied to clipboard

Fix for #84

Open ansel1 opened this issue 8 months ago • 2 comments

Adds support in the parser for treating JSON values specially. If the entire value is enclosed in curly braces or brackets, treat the value as a JSON string. Treat quotes and spaces inside the JSON value as literals.

ansel1 avatar Jun 25 '25 20:06 ansel1

Hi @ansel1, thank you for submitting a PR.

I don't think the parser should care about the format of the value. It doesn't matter if the value is JSON, TOML, valid to the spec, or invalid. We just want to be able to parse a value that contains double quotes, like a typical JSON, without escaping.

I added a comment on the issue. I'm happy to hear your thoughts.

allan2 avatar Jun 26 '25 04:06 allan2

I tend to agree, but I'm not sure how else other libraries would have implemented this. The rules inside probable JSON structures are just so different than the normal rules: spaces, double quotes and single quotes should be treated as literals, but substitution should still work (debatable I guess), and therefore slash-escape still needs to work...it's like a universe with different rules of physics.

Arguably, even the substitution and escape semantics should be disabled, and the entire value should be treated like a strong quote, since dotenv's escape character collides with JSON's.

That's why I put in the logic to only activate this mode when the entire value looks like a JSON object or array: to limit the blast radius of unintended side effects.

ansel1 avatar Jun 26 '25 18:06 ansel1