Skip to content

Commit

Permalink
ignore wildCardMinDistance when amount of nodes is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mchrome committed Dec 18, 2024
1 parent a088cee commit cbb12c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion finder/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ func (idx *IndexFinder) validatePlainQuery(query string, wildcardMinDistance int

var maxDist = where.MaxWildcardDistance(query)

if maxDist != -1 && maxDist < wildcardMinDistance {
// If the amount of nodes in a plain query is equal to 1,
// then make an exception
// This allows to check which root nodes exist
moreThanOneNode := strings.Count(query, ".") >= 1

if maxDist != -1 && maxDist < wildcardMinDistance && moreThanOneNode {
return errs.NewErrorWithCode("query has wildcards way too early at the start and at the end of it", http.StatusBadRequest)
}

Expand Down
10 changes: 9 additions & 1 deletion tests/wildcard_min_distance/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,12 @@ timeout = "1h"
targets = [
"*.*",
]
error_regexp = "^400: query has wildcards way too early at the start and at the end of it"
error_regexp = "^400: query has wildcards way too early at the start and at the end of it"

[[test.render_checks]]
from = "rnow-10"
until = "rnow+1"
timeout = "1h"
targets = [
"*",
]

0 comments on commit cbb12c8

Please sign in to comment.