diff --git a/tasks/actorstate/market/context.go b/tasks/actorstate/market/context.go index 58138b732..c1e1a2fc4 100644 --- a/tasks/actorstate/market/context.go +++ b/tasks/actorstate/market/context.go @@ -3,11 +3,8 @@ package market import ( "context" "fmt" - "strings" - "unicode/utf8" "github.com/filecoin-project/lotus/chain/types" - "golang.org/x/text/runes" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/tasks/actorstate" @@ -61,19 +58,3 @@ func NewMarketStateExtractionContext(ctx context.Context, a actorstate.ActorInfo func (m *MarketStateExtractionContext) IsGenesis() bool { return m.CurrTs.Height() == 0 } - -// SanitizeLabel ensures: -// - s is a valid utf8 string by removing any ill formed bytes. -// - s does not contain any nil (\x00) bytes because postgres doesn't support storing NULL (\0x00) characters in text fields. -func SanitizeLabel(s string) string { - if s == "" { - return s - } - s = strings.Replace(s, "\000", "", -1) - if utf8.ValidString(s) { - return s - } - - tr := runes.ReplaceIllFormed() - return tr.String(s) -} diff --git a/tasks/actorstate/market/context_test.go b/tasks/actorstate/market/context_test.go deleted file mode 100644 index e20ee3521..000000000 --- a/tasks/actorstate/market/context_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package market - -import ( - "strings" - "testing" - "unicode/utf8" - - "github.com/stretchr/testify/assert" -) - -func TestSanitizeLabel(t *testing.T) { - t.Run("valid utf8 string with null character", func(t *testing.T) { - stringWithNull := "golang\000" - goodString := SanitizeLabel(stringWithNull) - assert.False(t, strings.Contains(goodString, "\000")) - assert.True(t, utf8.ValidString(goodString)) - }) - - t.Run("invalid utf8 string", func(t *testing.T) { - invalidUtf8String := string([]byte("🌸")[:2]) - // sanity check - assert.False(t, utf8.ValidString(invalidUtf8String)) - - goodString := SanitizeLabel(invalidUtf8String) - assert.False(t, strings.Contains(goodString, "\000")) - assert.True(t, utf8.ValidString(goodString)) - }) - - t.Run("invalid utf8 string with null character", func(t *testing.T) { - invalidUtf8String := string([]byte("🌸")[:2]) - invalidUtf8String += "\000" - // sanity check - assert.False(t, utf8.ValidString(invalidUtf8String)) - - goodString := SanitizeLabel(invalidUtf8String) - assert.False(t, strings.Contains(goodString, "\000")) - assert.True(t, utf8.ValidString(goodString)) - }) - -}