Skip to content

Commit 070fb67

Browse files
committed
Reapply redaction algo fix
- Remove m.room.aliases from v4 algo - Only set preserved content keys if they exist (else they insert as 'null')
1 parent 3724c73 commit 070fb67

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

redactevent.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ var (
5454
"m.room.create": {"creator"},
5555
"m.room.join_rules": {"join_rule", "allow"},
5656
"m.room.power_levels": {"ban", "events", "events_default", "kick", "redact", "state_default", "users", "users_default"},
57-
"m.room.aliases": {"aliases"},
5857
"m.room.history_visibility": {"history_visibility"},
5958
}
6059
)
@@ -95,7 +94,10 @@ func redactEventJSON(eventJSON []byte, eventTypeToKeepContentFields map[string][
9594
newContent := map[string]interface{}{}
9695
keepContentFields := eventTypeToKeepContentFields[event.Type]
9796
for _, contentKey := range keepContentFields {
98-
newContent[contentKey] = event.Content[contentKey]
97+
val, ok := event.Content[contentKey]
98+
if ok {
99+
newContent[contentKey] = val
100+
}
99101
}
100102
// Replace the content with our new filtered content.
101103
// This will zero out any keys that weren't copied in the loop above.

redactevent_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ func TestRedactionAlgorithmV4(t *testing.T) {
3333
if !bytes.Equal(redactedv9, expectedv9) {
3434
t.Fatalf("room version 9 redaction produced unexpected result\nexpected: %s\ngot: %s", string(expectedv9), string(redactedv9))
3535
}
36+
37+
redactedv8withv9, err := MustGetRoomVersion(RoomVersionV9).RedactEventJSON(expectedv8)
38+
if err != nil {
39+
t.Fatal(err)
40+
}
41+
redactedv8withv9 = CanonicalJSONAssumeValid(redactedv8withv9)
42+
if !bytes.Equal(redactedv8withv9, expectedv8) {
43+
t.Fatalf("room version 8 redaction produced unexpected result\nexpected: %s\ngot: %s", string(expectedv8), string(redactedv8withv9))
44+
}
3645
}

0 commit comments

Comments
 (0)