mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Trimmed redirects (#230)
* Changes phrasing of redirects to be clearer. Now omits redirects if they are already listed as part of a larger redirect chain * Rebuilt how the redirection string is built. Now checks for duplicate redirections after all redirections have been read * Fixes intendation error * Fixed redirect output. * Fixed recording redirects. Co-authored-by: Jan Höfelmeyer <Jan Höfelmeyer jhoefelmeyer@intevation.de> Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de>
This commit is contained in:
parent
56a047cdde
commit
c00b8b37bb
2 changed files with 40 additions and 17 deletions
|
|
@ -11,6 +11,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
@ -76,19 +77,41 @@ func (r *redirectsReporter) report(p *processor, domain *Domain) {
|
|||
return
|
||||
}
|
||||
|
||||
keys := make([]string, len(p.redirects))
|
||||
var i int
|
||||
for k := range p.redirects {
|
||||
keys[i] = k
|
||||
i++
|
||||
keys := keysNotInValues(p.redirects)
|
||||
|
||||
first := func(i int) string {
|
||||
if vs := p.redirects[keys[i]]; len(vs) > 0 {
|
||||
return vs[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
sort.Slice(keys, func(i, j int) bool { return first(i) < first(j) })
|
||||
|
||||
for i, k := range keys {
|
||||
keys[i] = fmt.Sprintf("Redirect %s: %s", k, p.redirects[k])
|
||||
keys[i] = fmt.Sprintf("Redirect %s -> %s", strings.Join(p.redirects[k], " -> "), k)
|
||||
}
|
||||
req.message(WarnType, keys...)
|
||||
}
|
||||
|
||||
// keysNotInValues returns a slice of keys which are not in the values
|
||||
// of the given map.
|
||||
func keysNotInValues(m map[string][]string) []string {
|
||||
values := map[string]bool{}
|
||||
for _, vs := range m {
|
||||
for _, v := range vs {
|
||||
values[v] = true
|
||||
}
|
||||
}
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
if !values[k] {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
// report tests if an provider-metadata.json are available and sets the
|
||||
// "message" field value of the "Requirement" struct as a result of that.
|
||||
func (r *providerMetadataReport) report(p *processor, domain *Domain) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue