diff --git a/common/conversations.go b/common/conversations.go index d4d5328a..f8feb359 100644 --- a/common/conversations.go +++ b/common/conversations.go @@ -168,13 +168,13 @@ type DefaultConversationStore struct { func NewDefaultConversationStore(acc *qgen.Accumulator) (*DefaultConversationStore, error) { co := "conversations" return &DefaultConversationStore{ - get: acc.Select(co).Columns("createdBy, createdAt, lastReplyBy, lastReplyAt").Where("cid=?").Prepare(), + get: acc.Select(co).Columns("createdBy,createdAt,lastReplyBy,lastReplyAt").Where("cid=?").Prepare(), getUser: acc.SimpleInnerJoin("conversations_participants AS cp", "conversations AS c", "cp.cid, c.createdBy, c.createdAt, c.lastReplyBy, c.lastReplyAt", "cp.cid=c.cid", "cp.uid=?", "c.lastReplyAt DESC, c.createdAt DESC, c.cid DESC", "?,?"), getUserCount: acc.Count("conversations_participants").Where("uid=?").Prepare(), delete: acc.Delete(co).Where("cid=?").Prepare(), deletePosts: acc.Delete("conversations_posts").Where("cid=?").Prepare(), deleteParticipants: acc.Delete("conversations_participants").Where("cid=?").Prepare(), - create: acc.Insert(co).Columns("createdBy, createdAt, lastReplyBy, lastReplyAt").Fields("?,UTC_TIMESTAMP(),?,UTC_TIMESTAMP()").Prepare(), + create: acc.Insert(co).Columns("createdBy,createdAt,lastReplyBy,lastReplyAt").Fields("?,UTC_TIMESTAMP(),?,UTC_TIMESTAMP()").Prepare(), addParticipant: acc.Insert("conversations_participants").Columns("uid,cid").Fields("?,?").Prepare(), count: acc.Count(co).Prepare(), }, acc.FirstError() @@ -251,10 +251,13 @@ func (s *DefaultConversationStore) GetUserExtra(uid, offset int) (cos []*Convers var q string idList := make([]interface{}, len(raw)) for i, co := range raw { + if i == 0 { + q = "?" + } else { + q += ",?" + } idList[i] = strconv.Itoa(co.ID) - q += "?," } - q = q[0 : len(q)-1] rows, err := qgen.NewAcc().Select("conversations_participants").Columns("uid,cid").Where("cid IN(" + q + ")").Query(idList...) if err != nil { diff --git a/common/parser.go b/common/parser.go index c3b319a3..27d9177d 100644 --- a/common/parser.go +++ b/common/parser.go @@ -29,7 +29,7 @@ var URLOpenUser = []byte("") var bytesSinglequote = []byte("'") var bytesGreaterthan = []byte(">") -var urlMention = []byte(" class='mention'") +var urlMention = []byte("'class='mention'") var URLClose = []byte("") var imageOpen = []byte("= 1 && video[0] != "" { media.Type = "raw" // TODO: Filter the URL to make sure no nasties end up in there - media.Body = "" + media.Body = "" return media, true } } if lastFrag := pathFrags[len(pathFrags)-1]; lastFrag != "" { // TODO: Write a function for getting the file extension of a string - if extarr := strings.Split(lastFrag, "."); len(extarr) >= 2 { - ext := extarr[len(extarr)-1] + ext := strings.TrimPrefix(filepath.Ext(lastFrag),".") + if len(ext) != 0 { if ImageFileExts.Contains(ext) { media.Type = "image" var sport string diff --git a/parser_test.go b/parser_test.go index 0438d9c2..168e26b3 100644 --- a/parser_test.go +++ b/parser_test.go @@ -231,6 +231,7 @@ func TestParser(t *testing.T) { l.Add("//"+u+"\n//"+u, ""+c.Site.URL+"
"+c.Site.URL+"") l.Add("http://"+u, ""+c.Site.URL+"") l.Add("https://"+u, ""+c.Site.URL+"") + l.Add("//"+u+"/attachs/sha256hash.png?sid=1&stype=forums", "") l.Add("//"+u+"/attachs/sha256hash?sid=1&stype=forums", "[Invalid URL]") l.Add("//"+u+"/attachs/s?sid=1&stype=forums", "[Invalid URL]") @@ -240,30 +241,36 @@ func TestParser(t *testing.T) { l.Add("//"+u+"/attachs/sha256hash.png", "") l.Add("//"+u+"/attachs/sha256hash.png?sid=1", "") l.Add("//"+u+"/attachs/sha256hash.png?stype=forums", "") + + l.Add("//"+u+"/attachs/sha256hash.txt?sid=1&stype=forums", "Attachment") + + l.Add("//example.com/image.png", "") + l.Add("https://example.com/image.png", "") + l.Add("http://example.com/image.png", "") } local("localhost") local("127.0.0.1") local("[::1]") - l.Add("https://www.youtube.com/watch?v=lalalalala", "") - //l.Add("https://www.youtube.com/watch?v=;","") - l.Add("https://www.youtube.com/watch?v=d;", "") - l.Add("https://www.youtube.com/watch?v=d;d", "") + l.Add("https://www.youtube.com/watch?v=lalalalala", "") + //l.Add("https://www.youtube.com/watch?v=;","") + l.Add("https://www.youtube.com/watch?v=d;", "") + l.Add("https://www.youtube.com/watch?v=d;d", "") l.Add("https://www.youtube.com/watch?v=alert()", "[Invalid URL]()") l.Add("https://www.youtube.com/watch?v=alert()()", "[Invalid URL]()()") l.Add("https://www.youtube.com/watch?v=js:alert()", "[Invalid URL]()") l.Add("https://www.youtube.com/watch?v='+><+'", "[Invalid URL]'+><+'") l.Add("https://www.youtube.com/watch?v='+onready='alert(\"\")'+'", "[Invalid URL]'+onready='alert(\"\")'+'") - l.Add(" https://www.youtube.com/watch?v=lalalalala", " ") - l.Add("https://www.youtube.com/watch?v=lalalalala tt", " tt") - l.Add("https://www.youtube.com/watch?v=lalalalala&d=haha", "") - l.Add("https://gaming.youtube.com/watch?v=lalalalala", "") - l.Add("https://gaming.youtube.com/watch?v=lalalalala&d=haha", "") - l.Add("https://m.youtube.com/watch?v=lalalalala", "") - l.Add("https://m.youtube.com/watch?v=lalalalala&d=haha", "") - l.Add("http://www.youtube.com/watch?v=lalalalala", "") - l.Add("//www.youtube.com/watch?v=lalalalala", "") - //l.Add("www.youtube.com/watch?v=lalalalala","") + l.Add(" https://www.youtube.com/watch?v=lalalalala", " ") + l.Add("https://www.youtube.com/watch?v=lalalalala tt", " tt") + l.Add("https://www.youtube.com/watch?v=lalalalala&d=haha", "") + l.Add("https://gaming.youtube.com/watch?v=lalalalala", "") + l.Add("https://gaming.youtube.com/watch?v=lalalalala&d=haha", "") + l.Add("https://m.youtube.com/watch?v=lalalalala", "") + l.Add("https://m.youtube.com/watch?v=lalalalala&d=haha", "") + l.Add("http://www.youtube.com/watch?v=lalalalala", "") + l.Add("//www.youtube.com/watch?v=lalalalala", "") + //l.Add("www.youtube.com/watch?v=lalalalala","") l.Add("#tid-1", "#tid-1") l.Add("##tid-1", "##tid-1") @@ -305,11 +312,11 @@ func TestParser(t *testing.T) { l.Add("@2 t", "[Invalid Profile] t") l.Add("@2 ", "[Invalid Profile] ") l.Add("@2 @2", "[Invalid Profile] [Invalid Profile]") - l.Add("@1", "@Admin") - l.Add(" @1", " @Admin") - l.Add("@1t", "@Admint") - l.Add("@1 ", "@Admin ") - l.Add("@1 @1", "@Admin @Admin") + l.Add("@1", "@Admin") + l.Add(" @1", " @Admin") + l.Add("@1t", "@Admint") + l.Add("@1 ", "@Admin ") + l.Add("@1 @1", "@Admin @Admin") l.Add("@0", "[Invalid Profile]") l.Add("@-1", "[Invalid Profile]1")