The formatter should allow for backticks within quotes and vice versa
Hi there, I had some pixel art in my _Caddyfile_ in a `respond` directive in `v2.9.1`, that seemed to trigger an issue with `caddy fmt` when updating to `v2.10.0`.
I think this patch might be the cause, here is a minimal reproduction of the issue:
- Caddyfile after
caddy fmt --overwriteon v2.9.1:
:8080 {
respond "`"
}
A caddy run will run an HTTP server and return a single backtick upon curl 127.0.0.1:8080.
- Caddyfile after
caddy fmt --overwriteon v2.10.0:
:8080 {
respond "`"}
A caddy run will fail with: Error: adapting config using caddyfile: Unexpected '}' because no matching opening brace, at Caddyfile:2.
Thanks, I would post a separate issue if you prefered. :)
Note: this seems to be only triggered by an uneven number of backticks.
Originally posted by @lowlevl in https://github.com/caddyserver/caddy/issues/6903#issuecomment-2843813201
I intend on working on this, but I will need some time
hey @lowlevl , do you have another example that causes this behavior? The solution seems suspiciously simple and I want to make sure it is correct. Thanks.
In the mean time @mholt what should the formatter's behavour be given a config like these: Case 1:
block { respond "`{...}`"}
Case 2:
block { respond `"{...}"`}
Case 3:
block { respond "`{...}"}
Case 4:
block { respond `"{...}`}
The changes I am making will change the behavour depending on the quotation and backticks. I think escaping will have to come into effect here, otherwise it would be difficult to determine where literal strings begin and end.
Hi there, I only stumbled upon this specific case, I don't have additional breakage cases to provide, sorry !
I have added a patch to address this case and now we just wait for maintainers to approve or request changes. I believe for more complex quote combinations, like quote within backticks within quotes, escaping may be required. @mholt please inform me of any other problems you might notice with the merge request so I can address them. Otherwise, feel free to close this issue after merge, thanks.