Skip to content

fix: use the last tag when the search value starts with a comma - #4892

Merged
thorsten merged 1 commit into
thorsten:mainfrom
arpitjain099:fix/tag-autocomplete-leading-comma
Nov 15, 2026
Merged

thorsten merged 1 commit into
thorsten:mainfrom
arpitjain099:fix/tag-autocomplete-leading-comma

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TagController::search() keeps the last comma-separated segment of the search value, so the admin tag autocomplete queries the tag being typed and not the whole field. The guard is if (strpos($autoCompleteValue, needle: ',')), which returns 0 when the value starts with a comma, so the split is skipped: a field reading , bar reaches Tags::getAllTags() intact, the query becomes tagging_name LIKE ', bar%', and no suggestions come back.

Same shape as #4883. This switches to str_contains() and adds a , Bar case beside the existing foo, Bar one, which only covers a comma away from index 0.

The 4.1 branch has the same line, written strpos((string) $autoCompleteValue, ','), so please let me know if a backport there would help.

Checklist

  • composer check passes (format, lint, static analysis)
  • composer test passes (9766 tests, 3 redis tests skipped, no redis extension here). pnpm test not run, no JS/TS changes
  • pnpm tsc and pnpm oxlint pass for TypeScript changes - n/a
  • New or changed behaviour is covered by tests
  • Database schema changes ship with an upgrade step in phpMyFAQ\Setup\Update - n/a
  • CHANGELOG.md is updated for user-facing changes - n/a, a bug fix rather than a user-visible feature
  • Dependency major version bumps: upstream changelog read, old APIs grepped for, build green - n/a

Summary by CodeRabbit

  • Bug Fixes
    • Tag search now correctly handles comma-separated input that begins with a comma. It uses the final value in the list to find matching tags and display suggestions, so searches such as “, Bar” return the expected results. This also makes tag suggestions more consistent when a search begins with an empty list entry.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Tag search now detects commas with str_contains(). A test verifies that a search beginning with a comma passes the final term in lowercase to tag lookup and returns the expected suggestions.

Changes: Tag Search

Layer / File(s) Summary
Comma detection and search test
phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/TagController.php, tests/phpMyFAQ/Controller/Administration/Api/TagControllerTest.php
search() detects commas with str_contains(). A test checks that input beginning with a comma uses the final term in lowercase and returns the expected suggestions with HTTP 200.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: thorsten

Merge Risk: Minimal · up to 552f8

Tag search now handles a search value that begins with a comma by using the last tag for suggestions. The change is small and covered by a test, and no merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change accurately. The PR switches the comma guard in TagController::search() from strpos() to str_contains(), so a search value that starts with a comma (for example, ", bar") now…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change accurately. The PR switches the comma guard in TagController::search() from strpos() to str_contains(), so a search value that starts with a comma (for example, ", bar") now uses the last comma-separated value for the tag lookup. The added test covers this case. The title is specific and matches the main change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 47c06649-de3b-4b3c-aeb8-ff1f2cd29ac8
Commits

Reviewing files that changed from the base of the PR and between a2ebb32 and 552f8a6.

Files selected for processing: 2

  • phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/TagController.php
  • tests/phpMyFAQ/Controller/Administration/Api/TagControllerTest.php

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@thorsten

Copy link
Copy Markdown
Owner

@arpitjain099 Thank you very much! A PR against 4.1 would be cool as well!

@thorsten
thorsten merged commit 5692c42 into thorsten:main Nov 15, 2026
11 checks passed
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.

2 participants