mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
60183c7c79
commit
1da4650143
2 changed files with 5 additions and 5 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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`)
|
||||
|
|
Loading…
Reference in a new issue