Count runes and not characters

This commit is contained in:
Andrea Maria Piana 2020-09-25 10:12:02 +02:00
parent 0ba4694f21
commit 200273aa0e
3 changed files with 5 additions and 5 deletions

View File

@ -1 +1 @@
0.62.4
0.62.5

View File

@ -166,7 +166,7 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
return errors.New("text can't be empty")
}
if len(message.Text) > maxChatMessageTextLength {
if len([]rune(message.Text)) > maxChatMessageTextLength {
return fmt.Errorf("text shouldn't be longer than %d", maxChatMessageTextLength)
}

View File

@ -1,7 +1,7 @@
package protocol
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/suite"
@ -101,7 +101,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
ChatId: "a",
Clock: 1,
Timestamp: 2,
Text: "some-text",
Text: strings.Repeat("É", maxChatMessageTextLength),
ResponseTo: "",
EnsName: "",
MessageType: protobuf.MessageType_ONE_TO_ONE,
@ -202,7 +202,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
ChatId: "a",
Clock: 1,
Timestamp: 2,
Text: fmt.Sprintf("%x", make([]byte, maxChatMessageTextLength/2+1)),
Text: strings.Repeat("É", maxChatMessageTextLength+1),
ResponseTo: "",
EnsName: "",
MessageType: protobuf.MessageType_ONE_TO_ONE,