Skip to content

Commit

Permalink
Fix: garbled characters caused by intercepting a string in maxbytes i…
Browse files Browse the repository at this point in the history
…nterceptor (#398)
  • Loading branch information
ethfoo committed Nov 2, 2022
1 parent c620367 commit de7dc61
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 3 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ require (
github.com/shirou/gopsutil/v3 v3.22.2
github.com/smartystreets-prototypes/go-disruptor v0.0.0-20200316140655-c96477fd7a6a
github.com/stretchr/testify v1.7.5
github.com/thinkeridea/go-extend v1.3.2
go.uber.org/atomic v1.7.0
go.uber.org/automaxprocs v0.0.0-20200415073007-b685be8c1c23
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
golang.org/x/text v0.3.7
Expand Down Expand Up @@ -94,7 +96,6 @@ require (
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v1.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/thinkeridea/go-extend v1.3.2 h1:0ZImRXpJc+wBNIrNEMbTuKwIvJ6eFoeuNAewvzONrI0=
github.com/thinkeridea/go-extend v1.3.2/go.mod h1:xqN1e3y1PdVSij1VZp6iPKlO8I4jLbS8CUuTySj981g=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
Expand Down
4 changes: 2 additions & 2 deletions pkg/interceptor/maxbytes/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package maxbytes

import (
"fmt"

"github.com/loggie-io/loggie/pkg/core/api"
"github.com/loggie-io/loggie/pkg/core/source"
"github.com/loggie-io/loggie/pkg/pipeline"
"github.com/thinkeridea/go-extend/exunicode/exutf8"
)

const Type = "maxbytes"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (i *Interceptor) Intercept(invoker source.Invoker, invocation source.Invoca
event := invocation.Event
body := event.Body()
if len(body) > i.config.MaxBytes {
event.Fill(event.Meta(), event.Header(), body[:i.config.MaxBytes])
event.Fill(event.Meta(), event.Header(), exutf8.RuneSub(body, 0, i.config.MaxBytes))
}
return invoker.Invoke(invocation)
}
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/thinkeridea/go-extend/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

252 changes: 252 additions & 0 deletions vendor/github.com/thinkeridea/go-extend/exunicode/exutf8/utf8.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ github.com/spf13/pflag
# github.com/stretchr/testify v1.7.5
## explicit; go 1.13
github.com/stretchr/testify/assert
# github.com/thinkeridea/go-extend v1.3.2
## explicit; go 1.13
github.com/thinkeridea/go-extend/exunicode/exutf8
# github.com/tklauser/go-sysconf v0.3.9
## explicit; go 1.13
github.com/tklauser/go-sysconf
Expand Down

0 comments on commit de7dc61

Please sign in to comment.