RocketChat / RocketChat/Rocket.Chat.ReactNative

Bug Fix: slugifyLikeString skips sanitization due to unassigned replace() result

Open Beginner friendly
#6,782 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 bug
Dominant language
TypeScript
Stars
2.4k
Forks
1.5k
Avg merge
1d 18h
Merged PRs (30d)
90

Description

Describe the Bug

The function slugifyLikeString in app/lib/database/utils.ts (around line 14) contains a bug where the replace() result is not assigned or returned.
Because of this, the string sanitization step is effectively skipped, and the unsanitized string (which may contain special characters) is passed directly to slugify().

Steps to Reproduce

Open app/lib/database/utils.ts.

Locate the slugifyLikeString function (lines 12–17).

Notice this line:

str?.replace(likeStringRegex, '_');

The result of replace() is not assigned back to str or returned.

This means the sanitization step does not take effect before the string is passed to slugify().

Expected Behavior

The line should assign the result of replace() back to the variable:

str = str?.replace(likeStringRegex, '_') ?? str;

OR
chain the operation like this:

const sanitized = str.replace(likeStringRegex, '_');
const slugified = slugify(sanitized);
return slugified;

The string should always be sanitized before being passed to slugify().

Actual Behavior

The replace() on line 14 does nothing because its result is ignored.

The raw string with special characters is passed directly to slugify().

The sanitization step is effectively skipped.

Rocket.Chat Server Version

N/A (Code bug fix)

Rocket.Chat App Version

4.67.0

Device Name

N/A

OS Version

N/A

Additional Context

File: app/lib/database/utils.ts

Impact: The slugifyLikeString function is used in:

  • app/lib/methods/search.ts
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts

Note: This bug means special characters may not be properly sanitized before slugification, which could lead to unexpected behavior in search and room merging functionality.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in app/lib/database/utils.ts at slugifyLikeString and inspect its callers in app/lib/methods/search.ts and app/lib/methods/helpers/mergeSubscriptionsRooms.ts. Confirm how the ignored replace() result affects slugification, then verify that special characters are sanitized before slugify() receives the value and that the affected call sites still behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.