Skip to content

Commit

Permalink
Merge 0083e20 into 5a86c82
Browse files Browse the repository at this point in the history
  • Loading branch information
tengattack committed Jan 25, 2019
2 parents 5a86c82 + 0083e20 commit 3269389
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grok.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (g *Grok) ParseTyped(pattern string, text string) (map[string]interface{},
continue
}
name := g.nameToAlias(segmentName)
if segmentType, ok := gr.typeInfo[segmentName]; ok {
if segmentType, ok := gr.typeInfo[name]; ok {
switch segmentType {
case "int":
captures[name], _ = strconv.Atoi(match[i])
Expand Down
13 changes: 12 additions & 1 deletion grok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestShortName(t *testing.T) {

m, err := g.Match("%{A}", "a")
if err != nil {
t.Fatal("a should match %%{A}: err=%s", err.Error())
t.Fatalf("a should match %%{A}: err=%s", err.Error())
}
if !m {
t.Fatal("%%{A} didn't match 'a'")
Expand Down Expand Up @@ -575,6 +575,17 @@ func TestParseTypedWithSemanticHomonyms(t *testing.T) {
}
}

func TestParseTypedWithAlias(t *testing.T) {
g, _ := NewWithConfig(&Config{NamedCapturesOnly: true})
if captures, err := g.ParseTyped("%{NUMBER:access.response_code:int}", `404`); err != nil {
t.Fatalf("error can not capture : %s", err.Error())
} else {
if captures["access.response_code"] != 404 {
t.Fatalf("%s should be %#v have %#v", "access.response_code", 404, captures["access.response_code"])
}
}
}

var resultNew *Grok

func BenchmarkNew(b *testing.B) {
Expand Down

0 comments on commit 3269389

Please sign in to comment.