This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Search: do not interpret content: as regex if it is quoted#57679
Merged
Conversation
Contributor
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 4a29682...4844000.
|
fkling
approved these changes
Oct 17, 2023
fkling
left a comment
Contributor
There was a problem hiding this comment.
Should probably add a changelog entry for that.
sourcegraph-release-bot
pushed a commit
that referenced
this pull request
Dec 12, 2023
We have some logic that annotates a `content:` node as regex if `patterntype:regex` is set. This allows us to do things like `content:^a:b`, since escaping colons used to be a significant part of how `content:` was used. However, another significant way `content:` is used is to just search for string literals that would otherwise be interpreted as search syntax. Like `content:"a and b"`. It's a pretty solid heuristic to not treat a quoted string as regex, especially since we now have `/.../`-delimited regex literals, which makes using `content:` for regex patterns largely unnecessary. This was causing an issue where a parsing roundtrip for code insights would mangle a query like `content:"TEST" patterntype:regex` to `content:/"TEST"/`, which is obviously not ideal. (cherry picked from commit b621b8b)
camdencheek
added a commit
that referenced
this pull request
Dec 13, 2023
…quoted (#58904) Search: do not interpret `content:` as regex if it is quoted (#57679) We have some logic that annotates a `content:` node as regex if `patterntype:regex` is set. This allows us to do things like `content:^a:b`, since escaping colons used to be a significant part of how `content:` was used. However, another significant way `content:` is used is to just search for string literals that would otherwise be interpreted as search syntax. Like `content:"a and b"`. It's a pretty solid heuristic to not treat a quoted string as regex, especially since we now have `/.../`-delimited regex literals, which makes using `content:` for regex patterns largely unnecessary. This was causing an issue where a parsing roundtrip for code insights would mangle a query like `content:"TEST" patterntype:regex` to `content:/"TEST"/`, which is obviously not ideal. (cherry picked from commit b621b8b) Co-authored-by: Camden Cheek <camden@ccheek.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
We have some logic that annotates a
content:node as regex ifpatterntype:regexis set. This allows us to do things likecontent:^a:b, since escaping colons used to be a significant part of howcontent:was used.However, another significant way
content:is used is to just search for string literals that would otherwise be interpreted as search syntax. Likecontent:"a and b". It's a pretty solid heuristic to not treat a quoted string as regex, especially since we now have/.../-delimited regex literals, which makes usingcontent:for regex patterns largely unnecessary.This was causing an issue where a parsing roundtrip for code insights would mangle a query like
content:"TEST" patterntype:regextocontent:/"TEST"/, which is obviously not ideal.Fixes #57323
Test plan
Added a unit test.