diff --git a/grpc/federation/cel/url.go b/grpc/federation/cel/url.go index a1c0495e..05c39cf1 100644 --- a/grpc/federation/cel/url.go +++ b/grpc/federation/cel/url.go @@ -2,11 +2,12 @@ package cel import ( "context" + "net/url" + "github.com/google/cel-go/cel" "github.com/google/cel-go/common/types" "github.com/google/cel-go/common/types/ref" "github.com/google/cel-go/common/types/traits" - "net/url" ) const URLPackageName = "url" @@ -381,6 +382,9 @@ func (lib *URLLibrary) CompileOptions() []cel.EnvOption { } v.Path, err = url.JoinPath(v.Path, paths...) + if err != nil { + return types.NewErr(err.Error()) + } return lib.toURLValue(v) }, @@ -448,10 +452,6 @@ func (lib *URLLibrary) CompileOptions() []cel.EnvOption { queryParams := v.Query() queryMap := map[ref.Val]ref.Val{} for key, values := range queryParams { - var valueList []ref.Val - for _, val := range values { - valueList = append(valueList, types.String(val)) - } queryMap[types.String(key)] = types.NewStringList(adapter, values) } diff --git a/grpc/federation/cel/url_test.go b/grpc/federation/cel/url_test.go index dc68a38f..809c2ba9 100644 --- a/grpc/federation/cel/url_test.go +++ b/grpc/federation/cel/url_test.go @@ -3,8 +3,6 @@ package cel_test import ( "context" "fmt" - "github.com/google/cel-go/common/types/traits" - "github.com/google/go-cmp/cmp/cmpopts" "net/url" "strings" "testing" @@ -12,7 +10,10 @@ import ( "github.com/google/cel-go/cel" "github.com/google/cel-go/common/types" "github.com/google/cel-go/common/types/ref" + "github.com/google/cel-go/common/types/traits" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + cellib "github.com/mercari/grpc-federation/grpc/federation/cel" ) @@ -425,7 +426,7 @@ func TestURLFunctions(t *testing.T) { }, }, { - name: "join path", + name: "url join path", expr: `grpc.federation.url.parse('https://example.com/path?query=1#fragment').joinPath(['/new'])`, cmp: func(got ref.Val) error { gotV, ok := got.Value().(*cellib.URL)