Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON label extraction field validation expression overly strict #6372

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix lexeer issue, it's value to have numbers inside the field (just n…
…ot at the start)

Also simplified logic
  • Loading branch information
splitice committed Jun 12, 2022
commit 6cdbaec3b35fbda6631de8ade8bdcc8d90ea4809
15 changes: 7 additions & 8 deletions pkg/logql/log/jsonexpr/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (sc *Scanner) lex(lval *JSONExprSymType) int {
return RSB
case r == '.':
return DOT
case isIdentifier(r):
case isStartIdentifier(r):
sc.unread()
lval.field = sc.scanField()
return FIELD
Expand All @@ -83,21 +83,20 @@ func (sc *Scanner) lex(lval *JSONExprSymType) int {
}
}

func isIdentifier(r rune) bool {
func isStartIdentifier(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || r == '_'
}

func isIdentifier(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_'
splitice marked this conversation as resolved.
Show resolved Hide resolved
}

func (sc *Scanner) scanField() string {
var str []rune

for {
r := sc.read()
if !isIdentifier(r) {
sc.unread()
break
}

if r == '.' || isEndOfInput(r) {
if !isIdentifier(r) || isEndOfInput(r) {
sc.unread()
break
}
Expand Down