caddy icon indicating copy to clipboard operation
caddy copied to clipboard

The formatter should allow for backticks within quotes and vice versa

Open keystroke3 opened this issue 8 months ago • 5 comments

          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 --overwrite on 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 --overwrite on 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

keystroke3 avatar May 04 '25 12:05 keystroke3

I intend on working on this, but I will need some time

keystroke3 avatar May 04 '25 12:05 keystroke3

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.

keystroke3 avatar May 24 '25 11:05 keystroke3

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.

keystroke3 avatar May 24 '25 14:05 keystroke3

Hi there, I only stumbled upon this specific case, I don't have additional breakage cases to provide, sorry !

lowlevl avatar May 25 '25 18:05 lowlevl

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.

keystroke3 avatar Jun 02 '25 13:06 keystroke3