Count runes and not characters
This commit is contained in:
parent
0ba4694f21
commit
200273aa0e
|
@ -166,7 +166,7 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
|
||||||
return errors.New("text can't be empty")
|
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)
|
return fmt.Errorf("text shouldn't be longer than %d", maxChatMessageTextLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
@ -101,7 +101,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
|
||||||
ChatId: "a",
|
ChatId: "a",
|
||||||
Clock: 1,
|
Clock: 1,
|
||||||
Timestamp: 2,
|
Timestamp: 2,
|
||||||
Text: "some-text",
|
Text: strings.Repeat("É", maxChatMessageTextLength),
|
||||||
ResponseTo: "",
|
ResponseTo: "",
|
||||||
EnsName: "",
|
EnsName: "",
|
||||||
MessageType: protobuf.MessageType_ONE_TO_ONE,
|
MessageType: protobuf.MessageType_ONE_TO_ONE,
|
||||||
|
@ -202,7 +202,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
|
||||||
ChatId: "a",
|
ChatId: "a",
|
||||||
Clock: 1,
|
Clock: 1,
|
||||||
Timestamp: 2,
|
Timestamp: 2,
|
||||||
Text: fmt.Sprintf("%x", make([]byte, maxChatMessageTextLength/2+1)),
|
Text: strings.Repeat("É", maxChatMessageTextLength+1),
|
||||||
ResponseTo: "",
|
ResponseTo: "",
|
||||||
EnsName: "",
|
EnsName: "",
|
||||||
MessageType: protobuf.MessageType_ONE_TO_ONE,
|
MessageType: protobuf.MessageType_ONE_TO_ONE,
|
||||||
|
|
Loading…
Reference in New Issue