fix: coerce boolean parameter in loadSurroundingMessages check#40162
fix: coerce boolean parameter in loadSurroundingMessages check#40162Kgupta62 wants to merge 2 commits into
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: c488033 The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThe method loadSurroundingMessages now coerces the showThreadMessages parameter from a string to a boolean (treating the string 'true' as true) before performing the Boolean validation, preventing a Match error when clients send the value as a string. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/server/methods/loadSurroundingMessages.ts`:
- Around line 33-37: The code currently coerces any string to false which hides
malformed inputs; instead, in the loadSurroundingMessages logic handle only
explicit 'true' and 'false' strings: if showThreadMessages === 'true' set it to
true, else if showThreadMessages === 'false' set it to false, otherwise leave it
unchanged so the subsequent check(showThreadMessages, Boolean) will throw for
invalid values; update the conditional around the showThreadMessages variable
(the existing typeof showThreadMessages === 'string' branch) to implement this
explicit two-value coercion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dfb2b40f-992d-4973-8656-557e83119cf7
📒 Files selected for processing (1)
apps/meteor/server/methods/loadSurroundingMessages.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/server/methods/loadSurroundingMessages.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/server/methods/loadSurroundingMessages.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/server/methods/loadSurroundingMessages.ts
📚 Learning: 2026-03-09T18:39:14.020Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:14.020Z
Learning: When implementing batch processing in server methods, favor a single data pass to collect both the items and any derived fields needed for validation. Use the same dataset for both validation and processing to avoid races between validation and execution, and document the approach in code comments. Apply this pattern to similar Meteor Rocket.Chat server methods under apps/meteor/server/methods to prevent race conditions and ensure consistent batch behavior.
Applied to files:
apps/meteor/server/methods/loadSurroundingMessages.ts
| if (typeof showThreadMessages === 'string') { | ||
| showThreadMessages = showThreadMessages === 'true'; | ||
| } | ||
|
|
||
| check(showThreadMessages, Boolean); |
There was a problem hiding this comment.
Do not coerce arbitrary strings to false.
Line 34 currently turns any non-'true' string into false, so malformed inputs (e.g., 'foo') silently pass validation on Line 37. Coerce only 'true'/'false' and let check reject anything else.
Suggested fix
- if (typeof showThreadMessages === 'string') {
- showThreadMessages = showThreadMessages === 'true';
- }
+ if (typeof showThreadMessages === 'string') {
+ if (showThreadMessages === 'true') {
+ showThreadMessages = true;
+ } else if (showThreadMessages === 'false') {
+ showThreadMessages = false;
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (typeof showThreadMessages === 'string') { | |
| showThreadMessages = showThreadMessages === 'true'; | |
| } | |
| check(showThreadMessages, Boolean); | |
| if (typeof showThreadMessages === 'string') { | |
| if (showThreadMessages === 'true') { | |
| showThreadMessages = true; | |
| } else if (showThreadMessages === 'false') { | |
| showThreadMessages = false; | |
| } | |
| } | |
| check(showThreadMessages, Boolean); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/meteor/server/methods/loadSurroundingMessages.ts` around lines 33 - 37,
The code currently coerces any string to false which hides malformed inputs;
instead, in the loadSurroundingMessages logic handle only explicit 'true' and
'false' strings: if showThreadMessages === 'true' set it to true, else if
showThreadMessages === 'false' set it to false, otherwise leave it unchanged so
the subsequent check(showThreadMessages, Boolean) will throw for invalid values;
update the conditional around the showThreadMessages variable (the existing
typeof showThreadMessages === 'string' branch) to implement this explicit
two-value coercion.
Fixes #40119
Problem
loadSurroundingMessagesmethod throwsMatch error: Expected boolean, got stringat line 32 because theshowThreadMessagesparameter arrives as a string instead of a boolean via DDP.Changes
In
apps/meteor/server/methods/loadSurroundingMessages.ts, added a type coercion before thecheck()call:This converts the string
"true"/"false"to a proper boolean before Meteor'scheck(showThreadMessages, Boolean)runs.AI Disclosure
Summary by CodeRabbit