(v *detail.VulnInfo)
| 143 | } |
| 144 | |
| 145 | func formatDesc(v *detail.VulnInfo) string { |
| 146 | table := []struct { |
| 147 | fmt string |
| 148 | val string |
| 149 | }{ |
| 150 | {"| id | %s |", v.Id}, |
| 151 | {"| --- | --- |", ""}, |
| 152 | {"| cve | %s |", v.Cve}, |
| 153 | {"| cnnvd | %s |", v.Cnnvd}, |
| 154 | {"| cnvd | %s |", v.Cnvd}, |
| 155 | {"| cwe | %s |", v.Cwe}, |
| 156 | {"| level | %s |", v.SecurityLevel()}, |
| 157 | {"| desc | %s |", sanitizeString(v.Description)}, |
| 158 | {"| suggestion | %s |", sanitizeString(v.Suggestion)}, |
| 159 | } |
| 160 | var lines []string |
| 161 | for _, line := range table { |
| 162 | if strings.Contains(line.fmt, "%s") && line.val == "" { |
| 163 | continue |
| 164 | } |
| 165 | if line.val == "" { |
| 166 | lines = append(lines, line.fmt) |
| 167 | } else { |
| 168 | lines = append(lines, fmt.Sprintf(line.fmt, line.val)) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return strings.Join(lines, "\n") |
| 173 | } |
| 174 | |
| 175 | func sanitizeString(s string) string { |
| 176 | re := regexp.MustCompile("<[^>]*>") |
no test coverage detected