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

   ### Which Issue(s) This PR Fixes
   
   - Fixes #4289
   
   ### Brief Description
   
   `MybatisPlusAuditRepository.applyFilters` bound the raw search term into 
three `.like(...)` conditions (`operator`, `resource_name`, `detail`), so the 
search box value kept its LIKE wildcard meaning: `%` matched any run of 
characters and `_` matched any single character. Searching for `%` returned 
every audit row, `_` returned every row with a non-empty operator/resource 
name/detail, and a literal `_` or `%` (SQL text, `a_b`-style ids) could not be 
searched for at all.
   
   Every query in the repository is built from the same `applyFilters` helper — 
the paged list (`findPage`), the summary aggregates (`summarize`: result 
counts, `COUNT(DISTINCT operator)`, latest timestamp, both hotspot `GROUP BY`s) 
and therefore the CSV export through `AuditService.exportLogs` — so the 
wildcard reading also widened the insights and could push the export over its 
10 000-record cap, replacing the narrowed CSV with a 400.
   
   The pattern is now built from an escaped term (`\`, `%` and `_` escaped), 
the same way the existing `QueryHistoryService.escapeLike` house pattern does 
it, and the helper stays local to the file that needs it. A term without 
wildcard characters produces exactly the same pattern as before, so the 
existing `summarizeAppliesEveryFilterToEachAggregateQueryTest` expectations are 
unchanged.
   
   ### How Did You Test This Change?
   
   Test written first and run against the unmodified tree (`red`):
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MybatisPlusAuditRepositoryTest
   [ERROR] Tests run: 14, Failures: 2, Errors: 0, Skipped: 0
   [ERROR]   
MybatisPlusAuditRepositoryTest.findPageShouldEscapeLikeWildcardsInTheSearchTermTest:358
   Expecting ArrayList:
     ["%a%b_c\d%", "%a%b_c\d%", "%a%b_c\d%"]
   to contain only:
     ["%a\%b\_c\\d%"]
   [ERROR]   
MybatisPlusAuditRepositoryTest.summarizeShouldEscapeLikeWildcardsInTheSearchTermTest:381
   Expecting ArrayList:
     ["%50%_off%", "%50%_off%", "%50%_off%"]
   to contain only:
     ["%50\%\_off%"]
   [INFO] BUILD FAILURE
   ```
   
   After the fix (`green`), together with the audit service and controller 
tests:
   
   ```
   $ cd server && mvn -B -ntp test 
-Dtest=MybatisPlusAuditRepositoryTest,AuditServiceTest,AuditControllerTest
   [INFO] You have 0 Checkstyle violations.
   [INFO] Tests run: 41, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   Test coverage:
   
   - `findPageShouldEscapeLikeWildcardsInTheSearchTermTest` — searches for 
`a%b_c\d` and asserts all three bound parameters are the escaped 
`%a\%b\_c\\d%`, i.e. the wildcards are escaped and the backslash itself is 
escaped first.
   - `summarizeShouldEscapeLikeWildcardsInTheSearchTermTest` — captures all 
four `selectMaps` aggregate queries and the `selectList` latest-timestamp query 
and asserts each one binds the escaped `%50\%\_off%` for the three search 
columns, which is the "every query built from the search value" criterion in 
the issue.
   - Both tests capture the `QueryWrapper` with an `ArgumentCaptor` (calling 
`getSqlSegment()` before `getParamNameValuePairs()`) and assert the bound 
parameters, so they check the SQL that would actually 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