# HG changeset patch # User Mikael Berthe # Date 1536107603 -7200 # Node ID 741291bb47728844bc18996e4a67aef992f0a4c8 # Parent d13e9a780d917c84ceaf9518edbd11efeadfd5a3 Fix (hopefully) handling of arrays in API calls Item numbers should not be sent, except for two-dimension arrays. diff -r d13e9a780d91 -r 741291bb4772 account.go --- a/account.go Wed Sep 05 02:33:23 2018 +0200 +++ b/account.go Wed Sep 05 02:33:23 2018 +0200 @@ -362,7 +362,7 @@ if id < 1 { return nil, ErrInvalidID } - qID := fmt.Sprintf("id[%d]", i+1) + qID := fmt.Sprintf("id[%d]", i) params[qID] = strconv.FormatInt(id, 10) } diff -r d13e9a780d91 -r 741291bb4772 api.go --- a/api.go Wed Sep 05 02:33:23 2018 +0200 +++ b/api.go Wed Sep 05 02:33:23 2018 +0200 @@ -94,12 +94,13 @@ // It seems Mastodon doesn't like parameters with index // numbers, but it needs the brackets. // Let's check if the key matches '^.+\[.*\]$' + // Do not proceed if there's another bracket pair. klen := len(key) if klen == 0 { continue } i := strings.Index(key, "[") - if key[klen-1] == ']' && i > 0 { + if i > 0 && key[klen-1] == ']' && strings.Index(key[i+1:], "[") < 0 { // This is an array, let's remove the index number key = key[:i] + "[]" } diff -r d13e9a780d91 -r 741291bb4772 lists.go --- a/lists.go Wed Sep 05 02:33:23 2018 +0200 +++ b/lists.go Wed Sep 05 02:33:23 2018 +0200 @@ -100,7 +100,7 @@ if id < 1 { return ErrInvalidID } - qID := fmt.Sprintf("account_ids[%d]", i+1) + qID := fmt.Sprintf("account_ids[%d]", i) params[qID] = strconv.FormatInt(id, 10) } return mc.apiCall(endPoint, method, params, nil, nil, nil) @@ -115,7 +115,7 @@ if id < 1 { return ErrInvalidID } - qID := fmt.Sprintf("account_ids[%d]", i+1) + qID := fmt.Sprintf("account_ids[%d]", i) params[qID] = strconv.FormatInt(id, 10) } return mc.apiCall(endPoint, method, params, nil, nil, nil) diff -r d13e9a780d91 -r 741291bb4772 notifications.go --- a/notifications.go Wed Sep 05 02:33:23 2018 +0200 +++ b/notifications.go Wed Sep 05 02:33:23 2018 +0200 @@ -28,7 +28,7 @@ if len(excludeTypes) > 0 { params = make(apiCallParams) for i, eType := range excludeTypes { - qID := fmt.Sprintf("exclude_types[%d]", i+1) + qID := fmt.Sprintf("exclude_types[%d]", i) params[qID] = eType } } diff -r d13e9a780d91 -r 741291bb4772 report.go --- a/report.go Wed Sep 05 02:33:23 2018 +0200 +++ b/report.go Wed Sep 05 02:33:23 2018 +0200 @@ -36,7 +36,7 @@ if id < 1 { return nil, ErrInvalidID } - qID := fmt.Sprintf("status_ids[%d]", i+1) + qID := fmt.Sprintf("status_ids[%d]", i) params[qID] = strconv.FormatInt(id, 10) } diff -r d13e9a780d91 -r 741291bb4772 status.go --- a/status.go Wed Sep 05 02:33:23 2018 +0200 +++ b/status.go Wed Sep 05 02:33:23 2018 +0200 @@ -141,7 +141,7 @@ if id < 1 { return ErrInvalidID } - qID := fmt.Sprintf("media_ids[%d]", i+1) + qID := fmt.Sprintf("media_ids[%d]", i) params[qID] = strconv.FormatInt(id, 10) } if opts.Sensitive {