Skip to content

Commit

Permalink
chore: fix unicode error
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain committed Sep 11, 2023
1 parent 2e6211a commit 1f89d5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/xds/translator/jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package translator

import (
"fmt"
"strings"

clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
endpointv3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
Expand All @@ -29,6 +30,8 @@ const (
EmptyPath = ""
)

var unescaper = strings.NewReplacer(`\u00a0`, ` `)

// processJSONPatches applies each JSONPatch to the Xds Resources for a specific type.
func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*ir.EnvoyPatchPolicy) error {
var errs error
Expand Down Expand Up @@ -68,7 +71,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.ListenerType):
temp := &listenerv3.Listener{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, err.Error())
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand All @@ -81,7 +84,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.RouteType):
temp := &routev3.RouteConfiguration{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, err.Error())
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand All @@ -94,7 +97,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.ClusterType):
temp := &clusterv3.Cluster{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, err.Error())
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand All @@ -107,7 +110,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.EndpointType):
temp := &endpointv3.ClusterLoadAssignment{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, err.Error())
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand Down

0 comments on commit 1f89d5e

Please sign in to comment.