Skip to content

Commit

Permalink
http processor: replace space with + (#1499)
Browse files Browse the repository at this point in the history
* replace space with +

* add test

* address reviews
  • Loading branch information
maha-hajja authored Apr 19, 2024
1 parent 21b2f7c commit e2cd585
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkg/plugin/processor/builtin/impl/webhook/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -164,7 +165,16 @@ func (p *httpProcessor) EvaluateURL(rec opencdc.Record) (string, error) {
if err != nil {
return "", cerrors.Errorf("error while evaluating URL template: %w", err)
}
return b.String(), nil
u, err := url.Parse(b.String())
if err != nil {
return "", cerrors.Errorf("error parsing URL: %w", err)
}
q, err := url.ParseQuery(u.RawQuery)
if err != nil {
return "", cerrors.Errorf("error parsing URL query: %w", err)
}
u.RawQuery = q.Encode()
return u.String(), nil
}

func (p *httpProcessor) Process(ctx context.Context, records []opencdc.Record) []sdk.ProcessedRecord {
Expand Down
14 changes: 13 additions & 1 deletion pkg/plugin/processor/builtin/impl/webhook/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ func TestHTTPProcessor_URLTemplate(t *testing.T) {
},
}},
},
{
name: "URL template, path and query have spaces",
pathTmpl: `/{{.Payload.Before.url}}`,
path: "/what%20is%20conduit?id=my+id",
args: []opencdc.Record{{
Payload: opencdc.Change{
Before: opencdc.StructuredData{
"url": "what is conduit?id=my id",
},
},
}},
},
}

for _, tc := range tests {
Expand All @@ -407,7 +419,7 @@ func TestHTTPProcessor_URLTemplate(t *testing.T) {

srv := httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
// check the expected path with the evaluated URL
is.Equal(req.URL.Path, tc.path)
is.Equal(req.URL.String(), tc.path)
}))
defer srv.Close()

Expand Down

0 comments on commit e2cd585

Please sign in to comment.