caddy/caddyconfig
Roland b72bf7a1ef
caddyfile: keep an opening brace that ends the input (#8047)
* caddyfile: Keep an opening brace that ends the input

Format writes an opening brace lazily: the '{' case records the pending
brace and continues, and the brace is only emitted once a following
regular character is processed. When the input ends while a brace is
still pending, the read loop exits and nothing flushes it, so the brace
is dropped. 'caddy fmt' on a Caddyfile whose last line has just opened a
block therefore deletes the brace the user typed, and with --overwrite
that result is written back over the file.

Flush a pending brace after the loop ends. This also restores
idempotence for inputs such as '{ {', which formatted to '{' and then to
nothing.

* caddyfile: Flush a pending brace before another one replaces it

The '{' case overwrote the pending-brace state without emitting the
brace already waiting, so adjacent braces lost one: Format("{{") gave
just "{". Only the space-separated path flushed, and it did so with an
inline block.

Move that block into a flushOpenBrace closure and call it from the three
places a pending brace has to be emitted: the existing space-separated
path, the '{' case before it replaces the state, and the end of input.
Using it at the end of input also indents a trailing brace the same way
the other paths do.
2026-10-03 11:16:42 +10:00
..
caddyfile caddyfile: keep an opening brace that ends the input (#8047) 2026-10-03 11:16:42 +10:00
httpcaddyfile httpcaddyfile: new tls_automate_names global option (#8015) 2026-09-30 06:49:46 -04:00
warning admin: fix warnings and status code in /load API (#7267) 2026-09-23 08:55:38 -06:00
configadapters.go admin: fix warnings and status code in /load API (#7267) 2026-09-23 08:55:38 -06:00
httploader.go caddyconfig: cancel HTTP loader requests with context (#7918) 2026-08-10 15:12:47 +10:00
httploader_test.go caddyconfig: cancel HTTP loader requests with context (#7918) 2026-08-10 15:12:47 +10:00
load.go admin: fix warnings and status code in /load API (#7267) 2026-09-23 08:55:38 -06:00