← Back to PRs

#19304: fix(matrix): preserve room ID casing in directory resolution (#19278)

by lailoo open 2026-02-17 17:13 View on GitHub →
channel: matrix size: S experienced-contributor
## Summary - **Bug**: Per-room Matrix config (requireMention, autoReply) silently ignored due to room ID case mismatch - **Root cause**: `normalizeQuery()` in `directory-live.ts` lowercases room IDs/aliases before returning them, but `resolveChannelEntryMatch()` performs exact-case lookup at runtime - **Fix**: Preserve original casing for `!`-prefixed room IDs and `#`-prefixed aliases; only lowercase for fuzzy name search Fixes #19278 ## Problem When a user configures a Matrix room by its room ID (e.g. `!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org`), the directory resolution step in `listMatrixDirectoryGroupsLive()` passes the query through `normalizeQuery()` which calls `.toLowerCase()`. The lowercased ID becomes the key in the internal `roomsConfig` map. At runtime, Matrix events arrive with the original-case room ID. `resolveMatrixRoomConfig()` builds lookup candidates using this original-case ID and calls `resolveChannelEntryMatch()`, which uses `Object.prototype.hasOwnProperty.call(entries, key)` — an exact-case match. The lookup fails because `!araqdbw5...` ≠ `!ArAQdbw5...`. **Before fix:** ``` Input: "!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org" Output: "!araqdbw5b42r5ubhuwz84xs6gi:matrix.org" (lowercased) Config lookup: MISS → requireMention defaults to true ``` ## Changes - `extensions/matrix/src/directory-live.ts` — Use `trim()` instead of `normalizeQuery()` for the `!` and `#` code paths, preserving original casing. Only apply `toLowerCase()` for the fuzzy room-name search path where case-insensitive comparison is needed. - `extensions/matrix/src/directory-live.test.ts` — Add regression tests for room ID case preservation, alias case preservation, and fuzzy search lowercasing. - `CHANGELOG.md` — Add fix entry. **After fix:** ``` Input: "!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org" Output: "!ArAQdbw5b42R5uBHuWz84xs6GI:matrix.org" (preserved) Config lookup: HIT → requireMention: false applied correctly ``` ## Test plan - [x] New test: preserves original casing for `!`-prefixed room ID - [x] New test: preserves original casing for `#`-prefixed alias - [x] New test: lowercases query for fuzzy room name search (existing behavior) - [x] All 37 existing matrix tests pass - [x] Lint passes ## Effect on User Experience **Before:** Per-room settings like `requireMention: false` and `autoReply: true` are silently ignored for Matrix rooms configured by room ID. The bot requires a mention even when configured not to. **After:** Per-room settings are applied correctly regardless of room ID casing.

Most Similar PRs