fix(channels): add ok checks for type assertions in toChannelHashes
Two type assertions in toChannelHashes could panic when channel config values had unexpected types from JSON unmarshal: 1) value[enabled].(bool) panics if the key is missing or not a bool 2) vv.(map[string]string) panics when JSON unmarshal produces map[string]any. Add ok checks to safely handle both cases.
This commit is contained in:
parent
5224b9a4bc
commit
e5c7772d3c
1 changed files with 10 additions and 2 deletions
|
|
@ -17,7 +17,7 @@ func toChannelHashes(cfg *config.Config) map[string]string {
|
|||
_ = json.Unmarshal(marshal, &channelConfig)
|
||||
|
||||
for key, value := range channelConfig {
|
||||
if !value["enabled"].(bool) {
|
||||
if enabled, ok := value["enabled"].(bool); !ok || !enabled {
|
||||
continue
|
||||
}
|
||||
hiddenValues(key, value, ch.Get(key))
|
||||
|
|
@ -94,7 +94,15 @@ func hiddenValues(key string, value map[string]any, ch *config.Channel) {
|
|||
vv := value["webhooks"]
|
||||
webhooks := make(map[string]string)
|
||||
if vv != nil {
|
||||
webhooks = vv.(map[string]string)
|
||||
if m, ok := vv.(map[string]string); ok {
|
||||
webhooks = m
|
||||
} else if m, ok := vv.(map[string]any); ok {
|
||||
for k, w := range m {
|
||||
if s, ok := w.(string); ok {
|
||||
webhooks[k] = s
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if settings, ok := v.(*config.TeamsWebhookSettings); ok {
|
||||
for name, target := range settings.Webhooks {
|
||||
|
|
|
|||
Loading…
Reference in a new issue