From 37efe2659706e2a2c6f378ba69b3e8cce66a928f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 15 Jun 2016 23:22:33 +0200 Subject: Fuzzy matching --- bencode/bencode.go | 8 ++++---- bencode/bencode_test.go | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bencode/bencode.go b/bencode/bencode.go index 2521287..db980f7 100644 --- a/bencode/bencode.go +++ b/bencode/bencode.go @@ -168,14 +168,14 @@ func (d *decodeState) unmarshalDict(v reflect.Value) { for d.data[d.off] != 'e' { key, n := parseString(d.data[d.off:]) d.off += n - var has bool + var found bool if v.CanSet() { t := v.Type() for i := 0; i < t.NumField(); i++ { f := t.Field(i) tag := f.Tag.Get("bencode") name, _ := parseTag(tag) - if name == key || f.Name == key { + if key == name || key == f.Name || key == strings.ToLower(f.Name) { if key == "info" { infoOff = d.off } @@ -183,12 +183,12 @@ func (d *decodeState) unmarshalDict(v reflect.Value) { if key == "info" { infoEnd = d.off } - has = true + found = true break } } } - if !has { + if !found { d.unmarshalField(reflect.Value{}) } } diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go index 8fb6856..8ef71fa 100644 --- a/bencode/bencode_test.go +++ b/bencode/bencode_test.go @@ -90,8 +90,7 @@ func TestUnmarshalPartial(t *testing.T) { for _, tc := range testCase { t.Log("Testing", tc.Torrent) var tor = struct { - Announce string `bencode:"announce"` - //Announce string + Announce string // `bencode:"announce"` }{} body, err := ioutil.ReadFile(tc.Torrent) if err != nil { -- cgit v1.2.3