Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Handler panic fixed (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam authored Jan 15, 2021
1 parent 8326dcc commit 53b61cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/http/handlers/generate/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/http/handlers/generate/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand All @@ -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)
Expand Down

0 comments on commit 53b61cf

Please sign in to comment.