Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 04:45 UTC
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.