summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--diff-pem2html.go11
-rw-r--r--tls-pem2html.go5
-rw-r--r--util/html.go14
3 files changed, 25 insertions, 5 deletions
diff --git a/diff-pem2html.go b/diff-pem2html.go
index 542b829..f3b25ff 100644
--- a/diff-pem2html.go
+++ b/diff-pem2html.go
@@ -7,6 +7,8 @@ import (
"html/template"
"io/ioutil"
"os"
+
+ "./util"
)
func handleErr(err error, str string, a ...interface{}) {
@@ -24,14 +26,17 @@ func handleBool(ok bool, str string, a ...interface{}) {
}
}
-var tmpl = template.Must(template.New("2html").Parse(`<table class=diff>
+var tmpl = template.Must(template.New("pem2html").
+ Funcs(template.FuncMap{
+ "htmlcell": util.HTMLCellEscapeString,
+ }).Parse(`<table class=diff>
<tr class="diff-del"><td colspan=4>--- tls.pem</td></tr>
<tr class="diff-add"><td colspan=4>+++ crtsh.pem</td></tr>
<tr class="diff-dat"><td colspan=4>@@ -1,{{.nTLS}} +1,{{.nCrtSh}} @@</td></tr>
{{range $cert := .certs}}
<tr class={{$cert.Class}}>
- <td><a href="{{$cert.Url}}">{{if eq $cert.Pfix " "}}&nbsp;{{else}}{{$cert.Pfix}}{{end}}</a></td>
- <td><a href="{{$cert.Url}}">{{$cert.X509.Subject.CommonName}}</a></td>
+ <td><a href="{{$cert.Url}}">{{$cert.Pfix | htmlcell}}</a></td>
+ <td><a href="{{$cert.Url}}">{{$cert.X509.Subject.CommonName | htmlcell}}</a></td>
<td><a href="{{$cert.Url}}">{{$cert.X509.NotBefore.Local.Format "2006-01-02 15:04:05"}}</a></td>
<td><a href="{{$cert.Url}}">{{$cert.X509.NotAfter.Local.Format "2006-01-02 15:04:05"}}</a></td>
</tr>
diff --git a/tls-pem2html.go b/tls-pem2html.go
index d12504b..bc14f9a 100644
--- a/tls-pem2html.go
+++ b/tls-pem2html.go
@@ -35,6 +35,7 @@ var tmpl = template.Must(template.New("pem2html").
"date": util.Date2HTML,
"datetime": util.DateTime2HTML,
"colorDatetime": util.DateTime2ColorHTML,
+ "htmlcell": util.HTMLCellEscapeString,
}).Parse(`<table class=sortable>
<caption>
<p>Live Certs (Updated {{.now | colorDatetime}})</p>
@@ -49,8 +50,8 @@ var tmpl = template.Must(template.New("pem2html").
<tr class="{{$cert.Class}}">
<td style="background-color: {{$cert.X509.NotBefore | green}}"><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.NotBefore | date}}</a></td>
<td style="background-color: {{$cert.X509.NotAfter | red }}"><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.NotAfter | date}}</a></td>
- <td><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.Subject.CommonName | html}}</a></td>
- <td><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.Socket | html}}</a></td>
+ <td><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.Subject.CommonName | htmlcell}}</a></td>
+ <td><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.Socket | htmlcell}}</a></td>
</tr>
{{end}}
</table>
diff --git a/util/html.go b/util/html.go
new file mode 100644
index 0000000..af2ce60
--- /dev/null
+++ b/util/html.go
@@ -0,0 +1,14 @@
+package util
+
+import (
+ "html/template"
+ "strings"
+)
+
+func HTMLCellEscapeString(s string) template.HTML {
+ html := template.HTMLEscapeString(s)
+ if strings.TrimSpace(html) == "" {
+ html = "&nbsp;"
+ }
+ return template.HTML(html)
+}