Skip to content

Commit

Permalink
Merge pull request #223 from uptrace/fix/tagparser-braces
Browse files Browse the repository at this point in the history
fix(tagparser): improve parsing options with brackets
  • Loading branch information
vmihailenco committed Sep 27, 2021
2 parents ad165cb + 0daa61e commit cf07e55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/tagparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (p *parser) parseValue() string {
return p.parseQuotedValue()
case ',':
return p.s[start : p.i-1]
case '(':
p.skipPairs('(', ')')
}
}

Expand Down Expand Up @@ -125,6 +127,23 @@ func (p *parser) parseQuotedValue() string {
return ""
}

func (p *parser) skipPairs(start, end byte) {
var lvl int
for p.valid() {
switch c := p.read(); c {
case '"':
_ = p.parseQuotedValue()
case start:
lvl++
case end:
if lvl == 0 {
return
}
lvl--
}
}
}

func (p *parser) valid() bool {
return p.i < len(p.s)
}
Expand Down
1 change: 1 addition & 0 deletions internal/tagparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var tagTests = []struct {
{`hello:"D'Angelo, esquire",foo:bar`, "", map[string]string{"hello": "D'Angelo, esquire", "foo": "bar"}},
{`hello:"world('foo', 'bar')"`, "", map[string]string{"hello": "world('foo', 'bar')"}},
{" hello,foo: bar ", " hello", map[string]string{"foo": " bar "}},
{"type:geometry(POINT, 4326)", "", map[string]string{"type": "geometry(POINT, 4326)"}},
}

func TestTagParser(t *testing.T) {
Expand Down

0 comments on commit cf07e55

Please sign in to comment.