Conversation
SearchDTO.Check only preserved [tag] tokens made of \w characters and then replaced "-", ".", "+" and friends with spaces. A search for [react-native] reached the parser as [react native], no tag has that slug, so the tag filter was silently dropped and results came from every tag. New tags with spaces are saved with "-", so this hits any multi-word tag. Accept any non-space, non-bracket characters inside the brackets. Generated-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: n/a (no existing issue; details below)
Proposed Changes
[tag]search filter ("Advanced Search Tips":[tag] search with a tag) is silently ignored when the tag slug contains-,.,+or any other non-\wcharacter. Searching[react-native] navigationreturns matches from every tag instead of onlyreact-native. When a question is created, spaces in a new tag name are saved as-(question_service.go), so every multi-word tag is affected, along with slugs likenode.jsandc++.SearchDTO.Check→ReplaceSearchContentprotects[tag]tokens from the special-character cleanup, but only matches\[\w+\]. A token like[react-native]doesn't match, so the cleanup regex turns it into[react native].SearchParser.parseTagsthen looks up the slugreact native, finds no tag, skips it, and still strips the bracket token. The query then runs with no tag condition at all.ReplaceSearchContentnow accepts any non-space, non-bracket characters:\[[^\[\]\s]+\].parseTagsalready matches\[(.*?)\], so no other change is needed.internal/schema/search_schema_test.goadds[react-native] [node.js] [c++] navigation-bar. Ondev@6c00c788this becomes[react native] [node js] [c ] navigation bar; with the fix the tags stay intact.internal/repo/repo_test/search_tag_filter_test.go(new, ASF header) is an end-to-end test on the SQLite repo test DB. It creates tagssearch-hyphen-tagandsearch.dot.tagand two matching questions, only one of them tagged. It then runs the same path asGET /answer/api/v1/search:SearchDTO.Check→SearchParser.ParseStructure(realTagCommonService) →searchRepo.SearchContents. Ondevit fails withtag filter dropped, query became "[search hyphen tag] tagfilter". With the fix, only the tagged question is returned.go test ./internal/schema/ ./internal/repo/... ./internal/service/...passes, andgo vet,gofmtandgolangci-lintv2.6.2 report 0 issues.This bug was found and the fix and tests were written with AI assistance (Claude); I reviewed the change and ran the tests above.