Skip to content

fix(files): Escape search path filter and match the folder only - #67683

Open
kukanggg89 wants to merge 1 commit into
nextcloud:masterfrom
kukanggg89:fix-search-path-filter-67440
Open

kukanggg89 wants to merge 1 commit into
nextcloud:masterfrom
kukanggg89:fix-search-path-filter-67440

Conversation

@kukanggg89

Copy link
Copy Markdown
Contributor

Summary

Searching "in folder" /Photos also returned files from /Photos 2023 and /Photos-backup, because the path filter built its LIKE pattern from the raw folder name with no trailing slash. A _ or % in a folder name acted as a wildcard too.

FilesSearchProvider::buildSearchQuery() now builds the path comparison through a new buildPathSearchQuery() helper, which escapes the folder name with SearchComparison::escapeLikeParameter() and requires a trailing slash, so the pattern only matches the folder and its children. Searching the root folder is handled separately with a plain files/% pattern. This is the same shape CacheJail already uses.

apps/files/tests/Search/FilesSearchProviderTest.php gets a data-provider test asserting the built LIKE pattern for a plain folder, leading and trailing slashes, the root folder, and folder names containing _, %, and a backslash.

The term filter is left alone. The issue notes it is unescaped too but possibly intended as a plain substring search, so that is out of scope here.

Verification: the new tests were not run locally, there is no PHP on the machine this change was made on, so CI has to run them. The LIKE patterns were checked by simulating old versus new patterns against folder paths: the new pattern matches the folder and its children only, while the old one also matched sibling folders and treated _ and % as wildcards.

TODO

No open TODOs.

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Tests (unit, integration, api and/or acceptance) are included
  • Screenshots before/after for front-end changes (n/a: no front-end change)
  • Documentation (manuals or wiki) has been updated or is not required (n/a: bugfix, no user-facing behavior change beyond the fix)
  • Backports requested where applicable (ex: critical bugfixes) (n/a: bugfix, not critical)
  • Labels added where applicable (ex: bug/enhancement, 3. to review, feature component) (n/a: maintainers set labels)
  • Milestone added for target branch/version (ex: 32.x for stable32) (n/a: maintainers set the milestone)

AI (if applicable)

Drafted with help from Claude. I reviewed and revised every change myself before opening this PR.

The path filter built its LIKE pattern from the raw folder name, so
searching in /Photos also matched /Photos 2023 and /Photos-backup,
and _ and % in a folder name acted as wildcards. Escape the folder
name with SearchComparison::escapeLikeParameter() and require a
trailing slash, so the pattern only matches the folder and its
children. The root folder is handled separately with a plain
files/% pattern.

Adds unit tests for the built LIKE pattern covering a plain folder,
leading and trailing slashes, the root folder, and folder names
containing _, % and backslash.

Fixes nextcloud#67440

Signed-off-by: parel <farelalfarizi89@gmail.com>

Assisted-by: Muse:Muse Spark 1.3
@kukanggg89
kukanggg89 requested a review from a team as a code owner December 4, 2026 07:34
@kukanggg89
kukanggg89 requested review from GhassenKefi and vlotysh and removed request for a team December 4, 2026 07:34

This branch has not been deployed

No deployments
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.

Unified search "in folder" filter also matches sibling folders and treats _ and % as wildcards

1 participant