diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b1e9247..abd8bf8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## v4.0.1 + +### Fixed + +- Mistake inside HTTP script generation handler (it caused handler panic when "excludes list" less than "sources list") + ## v4.0.0 ### Changed diff --git a/internal/pkg/http/handlers/generate/handler.go b/internal/pkg/http/handlers/generate/handler.go index 1c479e79..0113510b 100644 --- a/internal/pkg/http/handlers/generate/handler.go +++ b/internal/pkg/http/handlers/generate/handler.go @@ -137,7 +137,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { //nolint:f if len(params.excluded) > 0 { h.writeComment(w, "Excluded hosts:") - for i := 0; i < len(params.sources); i++ { + for i := 0; i < len(params.excluded); i++ { h.writeComment(w, fmt.Sprintf(" - %s", params.excluded[i])) } } diff --git a/internal/pkg/http/handlers/generate/handler_test.go b/internal/pkg/http/handlers/generate/handler_test.go index 35d00975..953d6c3f 100644 --- a/internal/pkg/http/handlers/generate/handler_test.go +++ b/internal/pkg/http/handlers/generate/handler_test.go @@ -118,6 +118,7 @@ func TestHandler_ServeHTTP(t *testing.T) { "https%3A%2F%2Fmock%2Fad_servers.txt"+ ",http://mock/hosts_adaway.txt"+ ",http://non-existing-file.txt"+ + ",http://non-existing-file2.txt"+ "&excluded_hosts="+ "aaa.com"+ ",bbb.org"+ @@ -132,6 +133,7 @@ func TestHandler_ServeHTTP(t *testing.T) { assert.Regexp(t, `Cache.+miss.+http:\/\/mock\/hosts_adaway\.txt`, body) assert.Regexp(t, `Cache.+miss.+https:\/\/mock\/ad_servers\.txt`, body) assert.Regexp(t, `Source.+non-existing-file\.txt.+404`, body) + assert.Regexp(t, `Source.+non-existing-file2\.txt.+404`, body) assert.Regexp(t, `(?sU)Excluded hosts.+aaa\.com.+bbb\.org.+localhost`, rr.Body.String()) assert.Contains(t, body, "/ip dns static") assert.Equal(t, strings.Count(body, "add address=127.0.0.5 comment=\"foo\" disabled=no"), 1234)