Repository navigation
check for undesirable quotes - #260
Merged
Merged
Conversation
mbrt
requested changes
Jun 16, 2022
mbrt
left a comment
Owner
There was a problem hiding this comment.
Thanks for your contribution! I left some comments to simplify things a bit. Hopefully it's helpful.
Contributor
Author
|
@mbrt thank you for your help and patience. |
mbrt
requested changes
Jun 18, 2022
mbrt
requested changes
Jun 20, 2022
Contributor
Author
|
I think this is finally "correct" and I have squashed and reworded my commits appropriately. |
mbrt
requested changes
Jun 20, 2022
mbrt
left a comment
Owner
There was a problem hiding this comment.
Thanks for the changes! We're almost there.
mbrt
approved these changes
Jun 20, 2022
Owner
|
Thank you @mefuller! This is good to go. |
Contributor
Author
|
Thank you @mbrt |
gpechenik
pushed a commit
to gpechenik/gmailctl
that referenced
this pull request
Oct 4, 2026
Gmail's search syntax has no way to escape a double quote, so a `"` inside a value can only be valid as a pair around the whole value, e.g. subject: '"hello world"'. Since bc6bb81 such values are passed through unchanged, which fixed the example originally reported in mbrt#66. Any other quote still produced a malformed query without warning: subject: 'say "hi" now' -> subject:"say "hi" now" subject: '"unbalanced start' -> subject:""unbalanced start" from: 'foo"bar' -> from:foo"bar has: '"exact phrase" other' -> ""exact phrase" other" The pass-through check also only looked at the first and last characters, so '"foo" OR "bar"' was treated as a single phrase. Nested in a larger query it rendered as `subject:"foo" OR "bar"`, where "bar" matches anywhere in the message, not only in the subject. Make quote() accept a quote only when the value is exactly one quoted phrase (the new filter.IsQuoted), and fail otherwise, with a note on how to fix the config: remove the quotes (they are added automatically when needed), or write raw Gmail syntax with `isEscaped: true` or `query`, which are not checked. A similar check was added in mbrt#260 and reverted in mbrt#299, because it rejected every quote, including values wrapped as a whole, which users rely on to force an exact match (e.g. to: '"foo+bar"'). Those keep working: the new check only rejects values that already generated broken queries. Configs containing them will now fail to apply until fixed, which is intended, but worth a release note. `gmailctl test` also treated the quotes around a phrase as literal text, so rules like subject: '"hello world"' or to: '"foo+bar"' failed their own tests, even though Gmail matches them. The evaluators now strip those quotes before matching, using the same IsQuoted check. Close mbrt#66.
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 #66.
It's also my first attempt to meaningfully work on go/golang, so any guidance or pointers are very appreciated
Since processed strings are enclosed in outer double quotes, I test for a double quote contained anywhere as well as for enclosing single quotes, which would then be captured inside double quotes and result in a mismatch
Thanks