add a few more parser tests
save bytes in the parser save allocs in external image embeds in the parser save alloc bytes in convos
This commit is contained in:
parent
d3b2721746
commit
48b0b410c9
|
@ -251,10 +251,13 @@ func (s *DefaultConversationStore) GetUserExtra(uid, offset int) (cos []*Convers
|
||||||
var q string
|
var q string
|
||||||
idList := make([]interface{}, len(raw))
|
idList := make([]interface{}, len(raw))
|
||||||
for i, co := range raw {
|
for i, co := range raw {
|
||||||
idList[i] = strconv.Itoa(co.ID)
|
if i == 0 {
|
||||||
q += "?,"
|
q = "?"
|
||||||
|
} else {
|
||||||
|
q += ",?"
|
||||||
|
}
|
||||||
|
idList[i] = strconv.Itoa(co.ID)
|
||||||
}
|
}
|
||||||
q = q[0 : len(q)-1]
|
|
||||||
|
|
||||||
rows, err := qgen.NewAcc().Select("conversations_participants").Columns("uid,cid").Where("cid IN(" + q + ")").Query(idList...)
|
rows, err := qgen.NewAcc().Select("conversations_participants").Columns("uid,cid").Where("cid IN(" + q + ")").Query(idList...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var URLOpenUser = []byte("<a rel='ugc'href='")
|
||||||
var URLOpen2 = []byte("'>")
|
var URLOpen2 = []byte("'>")
|
||||||
var bytesSinglequote = []byte("'")
|
var bytesSinglequote = []byte("'")
|
||||||
var bytesGreaterthan = []byte(">")
|
var bytesGreaterthan = []byte(">")
|
||||||
var urlMention = []byte(" class='mention'")
|
var urlMention = []byte("'class='mention'")
|
||||||
var URLClose = []byte("</a>")
|
var URLClose = []byte("</a>")
|
||||||
var imageOpen = []byte("<a href=\"")
|
var imageOpen = []byte("<a href=\"")
|
||||||
var imageOpen2 = []byte("\"><img src='")
|
var imageOpen2 = []byte("\"><img src='")
|
||||||
|
@ -557,7 +557,6 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse
|
||||||
|
|
||||||
sb.Write(URLOpen)
|
sb.Write(URLOpen)
|
||||||
sb.WriteString(menUser.Link)
|
sb.WriteString(menUser.Link)
|
||||||
sb.Write(bytesSinglequote)
|
|
||||||
sb.Write(urlMention)
|
sb.Write(urlMention)
|
||||||
sb.Write(bytesGreaterthan)
|
sb.Write(bytesGreaterthan)
|
||||||
sb.WriteByte('@')
|
sb.WriteByte('@')
|
||||||
|
@ -944,8 +943,8 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
|
||||||
|
|
||||||
if lastFrag := pathFrags[len(pathFrags)-1]; lastFrag != "" {
|
if lastFrag := pathFrags[len(pathFrags)-1]; lastFrag != "" {
|
||||||
// TODO: Write a function for getting the file extension of a string
|
// TODO: Write a function for getting the file extension of a string
|
||||||
if extarr := strings.Split(lastFrag, "."); len(extarr) >= 2 {
|
ext := strings.TrimPrefix(filepath.Ext(lastFrag),".")
|
||||||
ext := extarr[len(extarr)-1]
|
if len(ext) != 0 {
|
||||||
if ImageFileExts.Contains(ext) {
|
if ImageFileExts.Contains(ext) {
|
||||||
media.Type = "image"
|
media.Type = "image"
|
||||||
var sport string
|
var sport string
|
||||||
|
|
|
@ -231,6 +231,7 @@ func TestParser(t *testing.T) {
|
||||||
l.Add("//"+u+"\n//"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a><br><a href='"+fs+"'>"+c.Site.URL+"</a>")
|
l.Add("//"+u+"\n//"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a><br><a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||||
l.Add("http://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
l.Add("http://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||||
l.Add("https://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
l.Add("https://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
|
||||||
|
|
||||||
l.Add("//"+u+"/attachs/sha256hash.png?sid=1&stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
l.Add("//"+u+"/attachs/sha256hash.png?sid=1&stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
||||||
l.Add("//"+u+"/attachs/sha256hash?sid=1&stype=forums", "<red>[Invalid URL]</red>")
|
l.Add("//"+u+"/attachs/sha256hash?sid=1&stype=forums", "<red>[Invalid URL]</red>")
|
||||||
l.Add("//"+u+"/attachs/s?sid=1&stype=forums", "<red>[Invalid URL]</red>")
|
l.Add("//"+u+"/attachs/s?sid=1&stype=forums", "<red>[Invalid URL]</red>")
|
||||||
|
@ -240,6 +241,12 @@ func TestParser(t *testing.T) {
|
||||||
l.Add("//"+u+"/attachs/sha256hash.png", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
l.Add("//"+u+"/attachs/sha256hash.png", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
||||||
l.Add("//"+u+"/attachs/sha256hash.png?sid=1", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
l.Add("//"+u+"/attachs/sha256hash.png?sid=1", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
||||||
l.Add("//"+u+"/attachs/sha256hash.png?stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
l.Add("//"+u+"/attachs/sha256hash.png?stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
||||||
|
|
||||||
|
l.Add("//"+u+"/attachs/sha256hash.txt?sid=1&stype=forums", "<a download class='attach'href=\""+fs+"/attachs/sha256hash.txt?sid=1&stype=forums\">Attachment</a>")
|
||||||
|
|
||||||
|
l.Add("//example.com/image.png", "<a href=\"//example.com/image.png\"><img src='//example.com/image.png'class='postImage'></a>")
|
||||||
|
l.Add("https://example.com/image.png", "<a href=\"https://example.com/image.png\"><img src='https://example.com/image.png'class='postImage'></a>")
|
||||||
|
l.Add("http://example.com/image.png", "<a href=\"http://example.com/image.png\"><img src='http://example.com/image.png'class='postImage'></a>")
|
||||||
}
|
}
|
||||||
local("localhost")
|
local("localhost")
|
||||||
local("127.0.0.1")
|
local("127.0.0.1")
|
||||||
|
|
Loading…
Reference in New Issue