Skip to content

Commit

Permalink
Merge pull request #711 from SSWConsulting/sanitise-csv
Browse files Browse the repository at this point in the history
Sanitize strings before writing tab-delimited CSV
  • Loading branch information
tombui99 committed Oct 19, 2023
2 parents 2438d9a + 072bfe7 commit e37f335
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docker/sswlinkauditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,23 @@ func writeResultFile(allUrls map[string]LinkStatus) {

f.WriteString("Source" + "\t" + "Destination" + "\t" + "Status" + "\t" + "StatusCode" + "\t" + "Anchor" + "\n")
for _, v := range allUrls {
f.WriteString(v.srcUrl + "\t" + v.url + "\t" + v.status + "\t" + strconv.Itoa(v.statusCode) + "\t" + strings.ReplaceAll(v.anchor,"\"","") + "\n")
f.WriteString(sanitizeString(v.srcUrl) + "\t" + sanitizeString(v.url) + "\t" + sanitizeString(v.status) + "\t" + strconv.Itoa(v.statusCode) + "\t" + sanitizeString(v.anchor) + "\n")
}

f.Close()
}

func sanitizeString(s string) string {
replacer := strings.NewReplacer(
"\"", "",
"\t", " ",
"\r\n", "",
"\n", "",
);

return replacer.Replace(s);
}

func isLinkUnscannable(a string, unscannableLinks []string) bool {
for _, b := range unscannableLinks {
if strings.HasPrefix(strings.ToLower(a), strings.ToLower(b)) {
Expand Down

0 comments on commit e37f335

Please sign in to comment.