Skip to content

Commit

Permalink
Merge pull request #64 from willnix/master
Browse files Browse the repository at this point in the history
Add table tags to the whitelist.
  • Loading branch information
rtfb committed Apr 20, 2014
2 parents 9c7cf8b + be9cbc6 commit 3ca168f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions html.go
Expand Up @@ -69,10 +69,24 @@ var (
"sub",
"strong",
"strike",
"ul",
"ul",
"table",
"tr",
"td",
"th",
"thead",
"tbody",

}

alignments = []string{
"left",
"right",
"center",
}

urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+`
tagWhitelist = regexp.MustCompile(`^(<\/?(` + strings.Join(tags, "|") + `)>|<(br|hr)\s?\/?>)$`)
tagWhitelist = regexp.MustCompile(`^(<\/?(` + strings.Join(tags, "|") + `)(\salign="(` + strings.Join(alignments, "|") + `)")?>|<(br|hr)\s?\/?>)$`)
anchorClean = regexp.MustCompile(`^(<a\shref="` + urlRe + `"(\stitle="[^"<>]+")?\s?>|<\/a>)$`)
imgClean = regexp.MustCompile(`^(<img\ssrc="` + urlRe + `"(\swidth="\d{1,3}")?(\sheight="\d{1,3}")?(\salt="[^"<>]*")?(\stitle="[^"<>]*")?\s?\/?>)$`)
// TODO: improve this regexp to catch all possible entities:
Expand Down

0 comments on commit 3ca168f

Please sign in to comment.