Merge pull request #63 from aykhans/fix/empty-slice

🐛 Return empty brackets instead of null when slice length is 0
This commit is contained in:
Aykhan Shahsuvarov 2024-12-25 01:24:28 +04:00 committed by GitHub
commit 3d5834a6a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -79,7 +79,7 @@ func (config *RequestConfig) Print() {
t.AppendSeparator() t.AppendSeparator()
t.AppendRow(table.Row{"Cookies", string(utils.PrettyJSONMarshal(config.Cookies, 3, "", " "))}) t.AppendRow(table.Row{"Cookies", string(utils.PrettyJSONMarshal(config.Cookies, 3, "", " "))})
t.AppendSeparator() t.AppendSeparator()
t.AppendRow(table.Row{"Proxies Count", string(utils.PrettyJSONMarshal(config.Proxies, 3, "", " "))}) t.AppendRow(table.Row{"Proxies", string(utils.PrettyJSONMarshal(config.Proxies, 3, "", " "))})
t.AppendSeparator() t.AppendSeparator()
t.AppendRow(table.Row{"Proxy Check", !config.NoProxyCheck}) t.AppendRow(table.Row{"Proxy Check", !config.NoProxyCheck})
t.AppendSeparator() t.AppendSeparator()

View File

@ -17,6 +17,9 @@ func (t TruncatedMarshaller) MarshalJSON() ([]byte, error) {
if val.Kind() != reflect.Slice && val.Kind() != reflect.Array { if val.Kind() != reflect.Slice && val.Kind() != reflect.Array {
return json.Marshal(t.Value) return json.Marshal(t.Value)
} }
if val.Len() == 0 {
return []byte("[]"), nil
}
length := val.Len() length := val.Len()
if length <= t.MaxItems { if length <= t.MaxItems {