Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

strip null bytes from a text memo #353

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/github.com/stellar/horizon/db2/core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/base64"
"fmt"

"strings"

sq "github.com/Masterminds/squirrel"
"github.com/guregu/null"
"github.com/stellar/go/strkey"
Expand Down Expand Up @@ -52,7 +54,9 @@ func (tx *Transaction) Memo() null.String {
case xdr.MemoTypeMemoNone:
value, valid = "", false
case xdr.MemoTypeMemoText:
value, valid = utf8.Scrub(tx.Envelope.Tx.Memo.MustText()), true
scrubbed := utf8.Scrub(tx.Envelope.Tx.Memo.MustText())
notnull := strings.Join(strings.Split(scrubbed, "\x00"), "")
value, valid = notnull, true
case xdr.MemoTypeMemoId:
value, valid = fmt.Sprintf("%d", tx.Envelope.Tx.Memo.MustId()), true
case xdr.MemoTypeMemoHash:
Expand Down
12 changes: 12 additions & 0 deletions src/github.com/stellar/horizon/db2/core/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"testing"

"github.com/stellar/go/xdr"
"github.com/stellar/horizon/test"
)

Expand All @@ -27,3 +28,14 @@ func TestTransactionsQueries(t *testing.T) {
tt.Assert.Equal(int32(3), tx.LedgerSequence)
}
}

func TestMemo(t *testing.T) {
tt := test.Start(t).Scenario("base")
defer tt.Finish()

var tx Transaction

xdr.SafeUnmarshalBase64("AAAAAMvoFDdcyQrJAcBmRdyEnW6047pvlk4MS/4r0n/1WH8VAAAAZAACnMAAAAACAAAAAAAAAAEAAAARADEuMC4xb3dlcnJpZGUgbWUAAAAAAAABAAAAAQAAAACJzogbLxrrmN7N5JVQceSxl8jkED26RGzbyyRIpwTh6wAAAAoAAAAWaSBzaG91bGQgYmUgb3dlcnJpZGRlbgAAAAAAAQAAABVpIHNob3VsZCBiZSBvd2VycmlkZW4AAAAAAAAAAAAAAacE4esAAABA0GuCIEmKyQ2DRqt5+BOIqjVlHisjY6rK1IcOtzjIKCDgSAoiv5yhYe09PohBH91TXvAQ/LZJj5hVMihfMjtgCw==", &tx.Envelope)

tt.Assert.Equal("1.0.1owerride me", tx.Memo().String)
}
6 changes: 4 additions & 2 deletions src/github.com/stellar/horizon/ingest/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,14 @@ func (is *Session) ingestTransaction() {
if !is.Cursor.Transaction().IsSuccessful() {
return
}

is.Ingestion.Transaction(
is.Err = is.Ingestion.Transaction(
is.Cursor.TransactionID(),
is.Cursor.Transaction(),
is.Cursor.TransactionFee(),
)
if is.Err != nil {
return
}

for is.Cursor.NextOp() {
is.ingestOperation()
Expand Down