Skip to content

fix(studio): escape SQL LIKE wildcards in user search - #4227

Closed
jokerzsd wants to merge 1 commit into
apache:rocketmq-studiofrom
jokerzsd:fix/studio-user-search-like-escape
Closed

jokerzsd wants to merge 1 commit into
apache:rocketmq-studiofrom
jokerzsd:fix/studio-user-search-like-escape

Conversation

@jokerzsd

Copy link
Copy Markdown
Contributor

Summary

Fix the Studio user search treating _ and % in the query as SQL LIKE wildcards.

Problem

AuthService.listUsers passed the raw username search into MyBatis-Plus like("username", ...) without escaping. A search for admin_ matched adminX and admin% matched any suffix. Other search paths (e.g. message query history) already escape \, % and _.

Fix

Escape \, % and _ before building the LIKE condition, matching the existing escapeLike behavior.

Test plan

Added a focused escapeLike regression test. mvn test -Dtest=AuthServiceTest — 17 tests, 0 failures.

Fixes #4223

AuthService.listUsers passed the raw username search into MyBatis-Plus
like("username", ...) without escaping LIKE wildcards, so a search for
"admin_" matched "adminX" and "admin%" matched any suffix.

Escape \, % and _ before building the LIKE condition, matching the
escaping already used by the message query history search.

Fixes apache#4223

Signed-off-by: jokerzsd <2701819133@qq.com>

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good fix with proper escaping of SQL LIKE wildcards and a focused unit test. The implementation correctly handles the backslash escape ordering.


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Same LIKE-wildcard escape fix applied to AuthService.listUsers. The escapeLike method is correct (backslash → percent → underscore order). Tests cover the admin_ → adminX false-positive case.

Findings

  • [Info] AuthService.java:537 — escapeLike is now duplicated across 4+ classes. Consider a shared utility to prevent drift.

LGTM.

@lizhimins

Copy link
Copy Markdown
Member

Closing as a duplicate of #4224, which was opened about two hours earlier, keeps the helper private instead of widening it to package-private static, and asserts the escaped value at the binding-parameter level. It also contradicts the approach in your own #4236, which puts the helper in common/util/SqlLikeUtils — one shared utility is what we want here.

@lizhimins lizhimins closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants