diff options
author | Francis Lavoie <lavofr@gmail.com> | 2021-04-02 13:55:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 11:55:34 -0600 |
commit | 3401f91dbeae80d22c8df9a4a50de521c69c9e00 (patch) | |
tree | 8ebae5c31ed1f44c3f6aec76e2e45d3e851f1238 /caddyconfig/caddyfile | |
parent | eb3955a960a7185b9b5b3eed5be9dda2b97cee69 (diff) |
caddyfile: Normalize line endings before comparing fmt result (#4103)
Diffstat (limited to 'caddyconfig/caddyfile')
-rw-r--r-- | caddyconfig/caddyfile/adapter.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/caddyconfig/caddyfile/adapter.go b/caddyconfig/caddyfile/adapter.go index 7f5ebc5..5b80df3 100644 --- a/caddyconfig/caddyfile/adapter.go +++ b/caddyconfig/caddyfile/adapter.go @@ -67,14 +67,17 @@ func (a Adapter) Adapt(body []byte, options map[string]interface{}) ([]byte, []c // is any different from the input; empty warning and false otherwise. // TODO: also perform this check on imported files func formattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) { - formatted := Format(body) - if bytes.Equal(formatted, body) { + // replace windows-style newlines to normalize comparison + normalizedBody := bytes.Replace(body, []byte("\r\n"), []byte("\n"), -1) + + formatted := Format(normalizedBody) + if bytes.Equal(formatted, normalizedBody) { return caddyconfig.Warning{}, false } // find where the difference is line := 1 - for i, ch := range body { + for i, ch := range normalizedBody { if i >= len(formatted) || ch != formatted[i] { break } |