lib/logstorage: allow using ! in unescaped phrase

Previously the phrase filter with `!` was treated unexpectedly.
For example, `foo!bar` filter was treated at `foo AND NOT bar`,
while most users expect that it matches "foo!bar" phrase.

This commit aligns with users' expectations.
This commit is contained in:
Aliaksandr Valialkin 2024-09-29 11:14:12 +02:00
parent 60183c7c79
commit 1da4650143
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 5 additions and 5 deletions

View file

@ -889,7 +889,7 @@ func parseGenericFilter(lex *lexer, fieldName string) (filter, error) {
}
func getCompoundPhrase(lex *lexer, allowColon bool) (string, error) {
stopTokens := []string{"*", ",", "(", ")", "[", "]", "|", "!", ""}
stopTokens := []string{"*", ",", "(", ")", "[", "]", "|", ""}
if lex.isKeyword(stopTokens...) {
return "", fmt.Errorf("compound phrase cannot start with '%s'", lex.token)
}
@ -906,7 +906,7 @@ func getCompoundPhrase(lex *lexer, allowColon bool) (string, error) {
func getCompoundSuffix(lex *lexer, allowColon bool) string {
s := ""
stopTokens := []string{"*", ",", "(", ")", "[", "]", "|", "!", ""}
stopTokens := []string{"*", ",", "(", ")", "[", "]", "|", ""}
if !allowColon {
stopTokens = append(stopTokens, ":")
}
@ -918,7 +918,7 @@ func getCompoundSuffix(lex *lexer, allowColon bool) string {
}
func getCompoundToken(lex *lexer) (string, error) {
stopTokens := []string{",", "(", ")", "[", "]", "|", "!", ""}
stopTokens := []string{",", "(", ")", "[", "]", "|", ""}
if lex.isKeyword(stopTokens...) {
return "", fmt.Errorf("compound token cannot start with '%s'", lex.token)
}

View file

@ -946,8 +946,8 @@ func TestParseQuerySuccess(t *testing.T) {
f("foo-bar+baz*", `"foo-bar+baz"*`)
f("foo- bar", `"foo-" bar`)
f("foo -bar", `foo !bar`)
f("foo!bar", `foo !bar`)
f("foo:aa!bb:cc", `foo:aa !bb:cc`)
f("foo!bar", `"foo!bar"`)
f("foo:aa!bb:cc", `foo:"aa!bb:cc"`)
f(`foo:bar:baz`, `foo:"bar:baz"`)
f(`foo:(bar baz:xxx)`, `foo:bar foo:"baz:xxx"`)
f(`foo:(_time:abc or not z)`, `foo:"_time:abc" or !foo:z`)