change short links to 48 #79

This commit is contained in:
Umputun
2018-06-21 21:32:49 -05:00
parent c0003922af
commit ff982dbd71
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -65,7 +65,7 @@ const (
)
// Maximum length for URL text shortening.
const shortURLLen = 32
const shortURLLen = 48
// PrepareUntrusted pre-processes a comment received from untrusted source by clearing all
// autogen fields and reset everything users not supposed to provide
@@ -101,7 +101,8 @@ func (c *Comment) SetDeleted(mode DeleteMode) {
func (c *Comment) Sanitize() {
p := bluemonday.UGCPolicy()
p.AllowAttrs("class").Matching(regexp.MustCompile("^language-[a-zA-Z0-9]+$")).OnElements("code")
c.Text = shortenAutoLinks(p.Sanitize(c.Text), shortURLLen)
c.Text = p.Sanitize(c.Text)
c.Text = shortenAutoLinks(c.Text, shortURLLen)
c.Orig = p.Sanitize(c.Orig)
c.User.ID = template.HTMLEscapeString(c.User.ID)
c.User.Name = template.HTMLEscapeString(c.User.Name)
+1 -1
View File
@@ -30,7 +30,7 @@ func TestComment_Sanitize(t *testing.T) {
User: User{ID: `<a href="http://blah.com">username</a>`},
},
out: Comment{
Text: `blah <a href="https://www.reddit.com/r/golang/comments/8jdo2l/remark42_is_a_selfhosted_lightweight_and_simple/" rel="nofollow">https://www.reddit.com/r/gola...</a>` + "\n\t",
Text: `blah <a href="https://www.reddit.com/r/golang/comments/8jdo2l/remark42_is_a_selfhosted_lightweight_and_simple/" rel="nofollow">https://www.reddit.com/r/golang/comments/8jdo...</a>` + "\n\t",
User: User{ID: `&lt;a href=&#34;http://blah.com&#34;&gt;username&lt;/a&gt;`},
},
},