Skip to content

fix(search): do not regex-escape the UID used for file lookups - #390

Open
mklemme1 wants to merge 1 commit into
nextcloud:masterfrom
mklemme1:fix/cli-search-escaped-uid
Open

fix(search): do not regex-escape the UID used for file lookups#390
mklemme1 wants to merge 1 commit into
nextcloud:masterfrom
mklemme1:fix/cli-search-escaped-uid

Conversation

@mklemme1

Copy link
Copy Markdown

Fixes #389

SearchService::improveSearchRequest() assigned the output of FilesService::secureUsername() -- a regex-escaping helper -- to $this->userId, which is then used as a real user ID. For any user whose UID contains a dot (michael.klemme@example.org becomes michael.klemme@example.org), getFileFromId() threw NoUserException and improveSearchResult() silently dropped every file result, so the search returned empty.

This only affected code paths without a user session, i.e. occ fulltextsearch:search. In the web UI $this->userId comes from IUserSession and is unescaped, so the same query worked there.

Neither consumer of the field wants an escaped value: getFileFromId() needs a real UID, and substr($file->getPath(), 7 + strlen($this->userId)) needs the real length -- the escaped name is one character too long per dot, so the computed path would be truncated incorrectly even if the lookup succeeded. improveSearchRequest() is also reached after the constructor has already set the same field from the session as a plain UID, which is the field's contract.

馃 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

SearchService::improveSearchRequest() assigned the output of
FilesService::secureUsername() -- a regex-escaping helper -- to
$this->userId, which is then used as a real user ID. For any user whose
UID contains a dot (michael.klemme@example.org becomes
michael\.klemme@example.org), getFileFromId() threw NoUserException and
improveSearchResult() silently dropped every file result, so the search
returned empty.

This only affected code paths without a user session, i.e.
occ fulltextsearch:search. In the web UI $this->userId comes from
IUserSession and is unescaped, so the same query worked there.

Neither consumer of the field wants an escaped value: getFileFromId()
needs a real UID, and substr($file->getPath(), 7 + strlen($this->userId))
needs the real length -- the escaped name is one character too long per
dot, so the computed path would be truncated incorrectly even if the
lookup succeeded. improveSearchRequest() is also reached after the
constructor has already set the same field from the session as a plain
UID, which is the field's contract.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

occ fulltextsearch:search returns no results for users whose UID contains a dot

1 participant