Skip to content

Commit 7c772f1

Browse files
Enforce type, sender, state_key and room_id lengths using bytes rather than codepoints (#338)
This effectively reverts the change made in [5f66df0](5f66df0) to bytes instead of codepoints, since Synapse will now enforce the same after matrix-org/synapse#13710. History here is that Synapse originally calculated bytes in Python 2.x, started counting codepoints in Python 3.x pretty much by accident and then the spec was ambiguous after the fact (hence matrix-org/matrix-spec#1001). Rationale is that bytes are probably easier for implementations to manage and less likely to generate huge indexes for client-side databases (especially where limits might exist like LMDB). cc @reivilibre
1 parent a72a83f commit 7c772f1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

event.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,18 +727,18 @@ func (e *Event) CheckFields() error { // nolint: gocyclo
727727
}
728728
}
729729

730-
if l := len([]rune(fields.Type)); l > maxIDLength {
730+
if l := len(fields.Type); l > maxIDLength {
731731
return EventValidationError{
732732
Code: EventValidationTooLarge,
733-
Message: fmt.Sprintf("gomatrixserverlib: event type is too long, length %d codepoints > maximum %d codepoints", l, maxIDLength),
733+
Message: fmt.Sprintf("gomatrixserverlib: event type is too long, length %d bytes > maximum %d bytes", l, maxIDLength),
734734
}
735735
}
736736

737737
if fields.StateKey != nil {
738-
if l := len([]rune(*fields.StateKey)); l > maxIDLength {
738+
if l := len(*fields.StateKey); l > maxIDLength {
739739
return EventValidationError{
740740
Code: EventValidationTooLarge,
741-
Message: fmt.Sprintf("gomatrixserverlib: state key is too long, length %d codepoints > maximum %d codepoints", l, maxIDLength),
741+
Message: fmt.Sprintf("gomatrixserverlib: state key is too long, length %d bytes > maximum %d bytes", l, maxIDLength),
742742
}
743743
}
744744
}
@@ -765,10 +765,10 @@ func checkID(id, kind string, sigil byte) (err error) {
765765
)
766766
return
767767
}
768-
if l := len([]rune(id)); l > maxIDLength {
768+
if l := len(id); l > maxIDLength {
769769
err = EventValidationError{
770770
Code: EventValidationTooLarge,
771-
Message: fmt.Sprintf("gomatrixserverlib: %s ID is too long, length %d codepoints > maximum %d codepoints", kind, l, maxIDLength),
771+
Message: fmt.Sprintf("gomatrixserverlib: %s ID is too long, length %d bytes > maximum %d bytes", kind, l, maxIDLength),
772772
}
773773
return
774774
}

0 commit comments

Comments
 (0)