Skip to content

Commit

Permalink
Avoid double slash when join url and path (#5503) (#5517)
Browse files Browse the repository at this point in the history
  • Loading branch information
kel authored and ruflin committed Nov 9, 2017
1 parent ee862c0 commit 67e05fc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Correctly send configured `Host` header to the remote server. {issue}4842[4842]
- Fix missing ACK in redis output. {issue}5404[5404]
- Change add_kubernetes_metadata to attempt detection of namespace. {pull}5482[5482]
- Avoid double slash when join url and path {pull}5517[5517]

*Auditbeat*

Expand Down
4 changes: 2 additions & 2 deletions libbeat/outputs/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var (
errExpectedItemObject = errors.New("expected item response object")
errExpectedStatusCode = errors.New("expected item status code")
errUnexpectedEmptyObject = errors.New("empty object")
errExcpectedObjectEnd = errors.New("expected end of object")
errExpectedObjectEnd = errors.New("expected end of object")
errTempBulkFailure = errors.New("temporary bulk send failure")
)

Expand Down Expand Up @@ -505,7 +505,7 @@ func itemStatus(reader *jsonReader) (int, []byte, error) {
return 0, nil, err
}
if kind != dictEnd {
err = errExcpectedObjectEnd
err = errExpectedObjectEnd
logp.Err("Failed to parse bulk response item: %s", err)
return 0, nil, err
}
Expand Down
46 changes: 46 additions & 0 deletions libbeat/outputs/elasticsearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,49 @@ func TestClientWithHeaders(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 2, requestCount)
}

func TestAddToURL(t *testing.T) {
type Test struct {
url string
path string
pipeline string
params map[string]string
expected string
}
tests := []Test{
{
url: "localhost:9200",
path: "/path",
pipeline: "",
params: make(map[string]string),
expected: "localhost:9200/path",
},
{
url: "localhost:9200/",
path: "/path",
pipeline: "",
params: make(map[string]string),
expected: "localhost:9200/path",
},
{
url: "localhost:9200",
path: "/path",
pipeline: "pipeline_1",
params: make(map[string]string),
expected: "localhost:9200/path?pipeline=pipeline_1",
},
{
url: "localhost:9200/",
path: "/path",
pipeline: "",
params: map[string]string{
"param": "value",
},
expected: "localhost:9200/path?param=value",
},
}
for _, test := range tests {
url := addToURL(test.url, test.path, test.pipeline, test.params)
assert.Equal(t, url, test.expected)
}
}
3 changes: 3 additions & 0 deletions libbeat/outputs/elasticsearch/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func addToURL(url, path, pipeline string, params map[string]string) string {
if strings.HasSuffix(url, "/") && strings.HasPrefix(path, "/") {
url = strings.TrimSuffix(url, "/")
}
if len(params) == 0 && pipeline == "" {
return url + path
}
Expand Down

0 comments on commit 67e05fc

Please sign in to comment.