aboutsummaryrefslogtreecommitdiff
path: root/bencode
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-15 23:22:33 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-15 23:22:33 +0200
commit37efe2659706e2a2c6f378ba69b3e8cce66a928f (patch)
tree2933ea034f1b2f085034ee905b52feaba21725de /bencode
parenta84ee4bfd94ff3c7aac29f5f9a438f5e8adcfd18 (diff)
Fuzzy matching
Diffstat (limited to 'bencode')
-rw-r--r--bencode/bencode.go8
-rw-r--r--bencode/bencode_test.go3
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 {