@@ -721,29 +721,30 @@ func (e *Event) CheckFields() error { // nolint: gocyclo
721
721
panic (e .invalidFieldType ())
722
722
}
723
723
724
- if len (e .eventJSON ) > maxEventLength {
724
+ if l := len (e .eventJSON ); l > maxEventLength {
725
725
return EventValidationError {
726
726
Code : EventValidationTooLarge ,
727
- Message : fmt .Sprintf ("gomatrixserverlib: event is too long, length %d > maximum %d" , len ( e . eventJSON ) , maxEventLength ),
727
+ Message : fmt .Sprintf ("gomatrixserverlib: event is too long, length %d bytes > maximum %d bytes " , l , maxEventLength ),
728
728
}
729
729
}
730
730
731
- if len (fields .Type ) > maxIDLength {
731
+ if l := len ([] rune ( fields .Type )); l > maxIDLength {
732
732
return EventValidationError {
733
733
Code : EventValidationTooLarge ,
734
- Message : fmt .Sprintf ("gomatrixserverlib: event type is too long, length %d > maximum %d" , len ( fields . Type ) , maxIDLength ),
734
+ Message : fmt .Sprintf ("gomatrixserverlib: event type is too long, length %d codepoints > maximum %d codepoints " , l , maxIDLength ),
735
735
}
736
736
}
737
737
738
- if fields .StateKey != nil && len (* fields .StateKey ) > maxIDLength {
739
- return EventValidationError {
740
- Code : EventValidationTooLarge ,
741
- Message : fmt .Sprintf ("gomatrixserverlib: state key is too long, length %d > maximum %d" , len (* fields .StateKey ), maxIDLength ),
738
+ if fields .StateKey != nil {
739
+ if l := len ([]rune (* fields .StateKey )); l > maxIDLength {
740
+ return EventValidationError {
741
+ Code : EventValidationTooLarge ,
742
+ Message : fmt .Sprintf ("gomatrixserverlib: state key is too long, length %d codepoints > maximum %d codepoints" , l , maxIDLength ),
743
+ }
742
744
}
743
745
}
744
746
745
- _ , err := checkID (fields .RoomID , "room" , '!' )
746
- if err != nil {
747
+ if _ , err := checkID (fields .RoomID , "room" , '!' ); err != nil {
747
748
return err
748
749
}
749
750
@@ -793,11 +794,11 @@ func checkID(id, kind string, sigil byte) (domain string, err error) {
793
794
)
794
795
return
795
796
}
796
- if len (id ) > maxIDLength {
797
- err = fmt . Errorf (
798
- "gomatrixserverlib: %s ID is too long, length %d > maximum %d" ,
799
- kind , len ( id ) , maxIDLength ,
800
- )
797
+ if l := len ([] rune ( id )); l > maxIDLength {
798
+ err = EventValidationError {
799
+ Code : EventValidationTooLarge ,
800
+ Message : fmt . Sprintf ( "gomatrixserverlib: %s ID is too long, length %d codepoints > maximum %d codepoints" , kind , l , maxIDLength ) ,
801
+ }
801
802
return
802
803
}
803
804
return
0 commit comments