Merge pull request #64 from willnix/master

Add table tags to the whitelist.
pull/69/head
Vytautas Šaltenis 2014-04-20 23:15:54 +03:00
commit 3ca168f879
1 changed files with 16 additions and 2 deletions

18
html.go
View File

@ -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: