Skip to content

Commit 2feb378

Browse files
authored
Merge pull request #463 from adam-talos/TrimNumbersFromSequenceStore
Trim extra non-ascii characters that can arise from manually editing …
2 parents 4ffb52e + e161d08 commit 2feb378

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

filestore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"path"
2424
"strconv"
25+
"strings"
2526
"time"
2627

2728
"github.com/pkg/errors"
@@ -213,15 +214,15 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error)
213214
}
214215

215216
if senderSeqNumBytes, err := ioutil.ReadFile(store.senderSeqNumsFname); err == nil {
216-
if senderSeqNum, err := strconv.Atoi(string(senderSeqNumBytes)); err == nil {
217+
if senderSeqNum, err := strconv.Atoi(strings.Trim(string(senderSeqNumBytes), "\r\n")); err == nil {
217218
if err = store.cache.SetNextSenderMsgSeqNum(senderSeqNum); err != nil {
218219
return creationTimePopulated, errors.Wrap(err, "cache set next sender")
219220
}
220221
}
221222
}
222223

223224
if targetSeqNumBytes, err := ioutil.ReadFile(store.targetSeqNumsFname); err == nil {
224-
if targetSeqNum, err := strconv.Atoi(string(targetSeqNumBytes)); err == nil {
225+
if targetSeqNum, err := strconv.Atoi(strings.Trim(string(targetSeqNumBytes), "\r\n")); err == nil {
225226
if err = store.cache.SetNextTargetMsgSeqNum(targetSeqNum); err != nil {
226227
return creationTimePopulated, errors.Wrap(err, "cache set next target")
227228
}

filestore_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import (
1919
"fmt"
2020
"os"
2121
"path"
22+
"strconv"
2223
"strings"
2324
"testing"
2425
"time"
2526

27+
assert2 "github.com/stretchr/testify/assert"
2628
"github.com/stretchr/testify/require"
2729
"github.com/stretchr/testify/suite"
2830
)
@@ -62,3 +64,14 @@ func (suite *FileStoreTestSuite) TearDownTest() {
6264
func TestFileStoreTestSuite(t *testing.T) {
6365
suite.Run(t, new(FileStoreTestSuite))
6466
}
67+
68+
func TestStringParse(t *testing.T) {
69+
assert := assert2.New(t)
70+
i, err := strconv.Atoi(strings.Trim("00005\n", "\r\n"))
71+
assert.Nil(err)
72+
assert.Equal(5, i)
73+
74+
i, err = strconv.Atoi(strings.Trim("00006\r", "\r\n"))
75+
assert.Nil(err)
76+
assert.Equal(6, i)
77+
}

0 commit comments

Comments
 (0)