@marcel91200 / caddy Mirror · read-only / commits / 3401f91d
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddyfile: Normalize line endings before comparing fmt result (#4103)

Francis Lavoie committed Apr 2, 2021 at 13:55 UTC 3401f91dbeae80d22c8df9a4a50de521c69c9e00
1 file changed +6 -3
caddyconfig/caddyfile/adapter.go
+6 -3
@@ -67,14 +67,17 @@ func (a Adapter) Adapt(body []byte, options map[string]interface{}) ([]byte, []c
67 // is any different from the input; empty warning and false otherwise.
68 // TODO: also perform this check on imported files
69 func formattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) {
70 - formatted := Format(body)
71 - if bytes.Equal(formatted, body) {
70 + // replace windows-style newlines to normalize comparison
71 + normalizedBody := bytes.Replace(body, []byte("\r\n"), []byte("\n"), -1)
72 +
73 + formatted := Format(normalizedBody)
74 + if bytes.Equal(formatted, normalizedBody) {
75 return caddyconfig.Warning{}, false
76 }
77
78 // find where the difference is
79 line := 1
77 - for i, ch := range body {
80 + for i, ch := range normalizedBody {
81 if i >= len(formatted) || ch != formatted[i] {
82 break
83 }