Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

search: closing parens terminate quoted patterns#41455

Merged
rvantonder merged 2 commits into
mainfrom
backend-integration/rvt/fixup-quote-terminator
Sep 7, 2022
Merged

search: closing parens terminate quoted patterns#41455
rvantonder merged 2 commits into
mainfrom
backend-integration/rvt/fixup-quote-terminator

Conversation

@rvantonder

@rvantonder rvantonder commented Sep 7, 2022

Copy link
Copy Markdown
Contributor

Previously an expression like (foo AND /bar/) would treat the /bar/ part as a literal instead of a regular expression in standard mode. This PR fixes it to treat /bar/ as a regular expression.


Explanation, optional reading

This is because previous to standard mode, we didn't care whether any pattern is well-delineated (e.g., by /.../ or "...") since these terms were always literal. But when they should be well-delineated (e.g., previously only in regex mode) we had a check that such a well-delineated pattern should be followed by a recognized terminal, in this case, whitespace. We check a "followed-by" condition because that lets us be resilient to lexing e.g., /some/thing/ without the user needing to escape the inner /. But the "followed by a space" is insufficient: we also need to check a possible valid terminator ) for a well-delineated regex in standard mode, before giving up and claiming the fallback case, that the pattern is a literal.

It would be nice to separate out the pure token lexing at some point (similar to frontend code) because of the hybrid literal/regexp complexity in standard mode, but this change is sufficient to cover the buggy behavior.

Test plan

Added test

@cla-bot cla-bot Bot added the cla-signed label Sep 7, 2022
@rvantonder rvantonder marked this pull request as ready for review September 7, 2022 18:55
Comment on lines +24 to +26
"labels": [
"Regexp"
],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the important part of the output

@sourcegraph-bot

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 2d66e9c...3e1bebc.

Notify File(s)
@beyang internal/search/query/parser.go
internal/search/query/parser_test.go
internal/search/query/testdata/TestParseStandard/parens_around_/.../.golden
@camdencheek internal/search/query/parser.go
internal/search/query/parser_test.go
internal/search/query/testdata/TestParseStandard/parens_around_/.../.golden
@keegancsmith internal/search/query/parser.go
internal/search/query/parser_test.go
internal/search/query/testdata/TestParseStandard/parens_around_/.../.golden

@rvantonder rvantonder merged commit dd0ad55 into main Sep 7, 2022
@rvantonder rvantonder deleted the backend-integration/rvt/fixup-quote-terminator branch September 7, 2022 19:29
@coury-clark

Copy link
Copy Markdown
Contributor

@rvantonder Just curious, does this also address https://github.com/sourcegraph/sourcegraph/issues/40511? I suspect it may be the same thing from the description

@rvantonder

Copy link
Copy Markdown
Contributor Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants