mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Fix type assertions from directory_url expression result
This commit is contained in:
parent
8e13d37756
commit
050e225d07
3 changed files with 18 additions and 2 deletions
|
|
@ -918,7 +918,7 @@ func (p *processor) checkCSAFs(domain string) error {
|
||||||
p.badProviderMetadata.warn("extracting directory URLs failed: %v.", err)
|
p.badProviderMetadata.warn("extracting directory URLs failed: %v.", err)
|
||||||
} else {
|
} else {
|
||||||
var ok bool
|
var ok bool
|
||||||
dirURLs, ok = directoryURLs.([]string)
|
dirURLs, ok = util.AsStrings(directoryURLs)
|
||||||
if !ok {
|
if !ok {
|
||||||
p.badProviderMetadata.warn("directory URLs are not strings.")
|
p.badProviderMetadata.warn("directory URLs are not strings.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (afp *AdvisoryFileProcessor) Process(
|
||||||
lg("extracting directory URLs failed: %v\n", err)
|
lg("extracting directory URLs failed: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
var ok bool
|
var ok bool
|
||||||
dirURLs, ok = directoryURLs.([]string)
|
dirURLs, ok = util.AsStrings(directoryURLs)
|
||||||
if !ok {
|
if !ok {
|
||||||
lg("directory_urls are not strings.\n")
|
lg("directory_urls are not strings.\n")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
util/json.go
16
util/json.go
|
|
@ -166,3 +166,19 @@ func (pe *PathEval) Strings(
|
||||||
}
|
}
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AsStrings transforms an []interface{string, string,... }
|
||||||
|
// to a []string.
|
||||||
|
func AsStrings(x interface{}) ([]string, bool) {
|
||||||
|
strs, ok := x.([]interface{})
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
res := make([]string, 0, len(strs))
|
||||||
|
for _, y := range strs {
|
||||||
|
if s, ok := y.(string); ok {
|
||||||
|
res = append(res, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, true
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue