btlqql opened a new pull request, #4667:
URL: https://github.com/apache/rocketmq-dashboard/pull/4667

   ### Which Issue(s) This PR Fixes
   
   - Fixes #4232
   
   ### Brief Description
   
   `MybatisPlusAlertRepository` bound the raw search term into `.like(...)` in 
both paged rule feeds — `ruleQuery` 
(`server/src/main/java/org/apache/rocketmq/studio/ops/alert/MybatisPlusAlertRepository.java:84`)
 and `findRulesPage` (`:94` and `:96`) — so the term was interpreted as a LIKE 
pattern instead of as literal text: `%` matched any run of characters, `_` 
matched any single character, and `\` escaped whatever followed it. Searching 
for a rule whose name or metric contains a percent sign or an underscore 
therefore listed unrelated rules, and a term containing a backslash could match 
nothing at all.
   
   The pattern is now built from an escaped term (`\`, `%` and `_` escaped), 
the same way the existing `QueryHistoryService.escapeLike` house pattern does 
it, with the helper kept local to the file that needs it. Both paged searches 
are covered: `findRulePage` (name only) and `findRulesPage` (name OR metric). A 
term without wildcard characters produces exactly the same pattern as before, 
so the existing `hasBusinessRulePageFilters` expectation (`%lag%`) is unchanged.
   
   ### How Did You Test This Change?
   
   Test written first and run against the unmodified tree (`red`):
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MybatisPlusAlertRepositoryTest
   [ERROR] Tests run: 18, Failures: 2, Errors: 0, Skipped: 0
   [ERROR]   
MybatisPlusAlertRepositoryTest.findRulePageShouldEscapeLikeWildcardsInTheSearchTermTest:209
   Expecting actual:
     {"MPGENVAL1"="%a%b_c\d%"}
   to contain value:
     "%a\%b\_c\\d%"
   [ERROR]   
MybatisPlusAlertRepositoryTest.findRulesPageShouldEscapeLikeWildcardsInTheSearchTermTest:225
   Expecting actual:
     {"MPGENVAL1"=true, "MPGENVAL2"="%50%_off%", "MPGENVAL3"="%50%_off%", 
"MPGENVAL4"="BUSINESS"}
   to contain value:
     "%50\%\_off%"
   [ERROR] Tests run: 18, Failures: 2, Errors: 0, Skipped: 0
   [INFO] BUILD FAILURE
   ```
   
   After the fix (`green`):
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MybatisPlusAlertRepositoryTest
   [INFO] You have 0 Checkstyle violations.
   [INFO] Tests run: 18, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   Neighbouring classes, to show the change does not disturb the paged feeds or 
the controllers:
   
   ```
   $ cd server && mvn -B -ntp test 
-Dtest=AlertServiceTest,AlertRuleControllerTest,SystemAlertControllerTest,ClusterAlertRuleControllerTest,AlertRuleAssetServiceTest
   [INFO] Tests run: 133, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   Test coverage:
   
   - `findRulePageShouldEscapeLikeWildcardsInTheSearchTermTest` — searches for 
`a%b_c\d` and asserts the wrapper binds `%a\%b\_c\\d%`, i.e. the wildcard 
characters are escaped and the backslash itself is escaped first.
   - `findRulesPageShouldEscapeLikeWildcardsInTheSearchTermTest` — the 
name-or-metric feed: searching `" 50%_off "` binds the trimmed, escaped 
`%50\%\_off%` to both columns.
   - Both tests capture the `QueryWrapper` with an `ArgumentCaptor` (calling 
`getSqlSegment()` before `getParamNameValuePairs()`) and assert the bound 
parameter, so they exercise the SQL that would be sent and need no database.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`fix:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [x] New UI text has both Chinese and English entries under `web/src/i18n/` 
— not applicable, no UI text added
   - [x] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [x] New source files carry the ASF license header — no new source files
   - [x] Documentation touched where behaviour changed — not applicable, the 
search contract is unchanged for terms without wildcard characters
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to