diff --git a/common/parser.go b/common/parser.go index e590adc1..6df2f259 100644 --- a/common/parser.go +++ b/common/parser.go @@ -862,8 +862,7 @@ func parseMediaString(data string) (media MediaEmbed, ok bool) { port := url.Port() query := url.Query() - // TODO: Treat 127.0.0.1 and [::1] as localhost too - samesite := hostname == "localhost" || hostname == Site.URL + samesite := hostname == "localhost" || hostname == "127.0.0.1" || hostname == "::1" || hostname == Site.URL if samesite { hostname = strings.Split(Site.URL, ":")[0] // ?- Test this as I'm not sure it'll do what it should. If someone's running SSL on port 80 or non-SSL on port 443 then... Well... They're in far worse trouble than this... diff --git a/common/widget_wol.go b/common/widget_wol.go index bbb8ef94..8b273695 100644 --- a/common/widget_wol.go +++ b/common/widget_wol.go @@ -5,7 +5,7 @@ import ( //"log" "net/http/httptest" - "github.com/Azareal/Gosora/common/phrases" + p "github.com/Azareal/Gosora/common/phrases" min "github.com/Azareal/Gosora/common/templates" ) @@ -16,8 +16,8 @@ type wolUsers struct { UserCount int } -func wolInit(widget *Widget, schedule *WidgetScheduler) error { - schedule.Add(widget) +func wolInit(w *Widget, schedule *WidgetScheduler) error { + schedule.Add(w) return nil } @@ -34,22 +34,22 @@ func wolGetUsers() ([]*User, int) { return users, ucount } -func wolBuild(widget *Widget, hvars interface{}) (string, error) { +func wolBuild(w *Widget, hvars interface{}) (string, error) { users, ucount := wolGetUsers() - wol := &wolUsers{hvars.(*Header), phrases.GetTmplPhrase("widget.online_name"), users, ucount} + wol := &wolUsers{hvars.(*Header), p.GetTmplPhrase("widget.online_name"), users, ucount} err := wol.Header.Theme.RunTmpl("widget_online", wol, wol.Header.Writer) return "", err } -func wolRender(widget *Widget, hvars interface{}) (string, error) { - iTickMask := widget.TickMask.Load() +func wolRender(w *Widget, hvars interface{}) (string, error) { + iTickMask := w.TickMask.Load() if iTickMask != nil { tickMask := iTickMask.(*Widget) if tickMask != nil { return tickMask.Body, nil } } - return wolBuild(widget, hvars) + return wolBuild(w, hvars) } var wolLastUsers []*User @@ -88,7 +88,7 @@ func wolTick(widget *Widget) error { //log.Printf("users: %+v\n", users) //log.Printf("wolLastUsers: %+v\n", wolLastUsers) - wol := &wolUsers{SimpleDefaultHeader(w), phrases.GetTmplPhrase("widget.online_name"), users, ucount} + wol := &wolUsers{SimpleDefaultHeader(w), p.GetTmplPhrase("widget.online_name"), users, ucount} err := wol.Header.Theme.RunTmpl("widget_online", wol, wol.Header.Writer) if err != nil { return err diff --git a/common/widgets.go b/common/widgets.go index 1d40dd9a..c46c1d6b 100644 --- a/common/widgets.go +++ b/common/widgets.go @@ -48,7 +48,7 @@ type NameTextPair struct { Text template.HTML } -func preparseWidget(widget *Widget, wdata string) (err error) { +func preparseWidget(w *Widget, wdata string) (err error) { prebuildWidget := func(name string, data interface{}) (string, error) { var b bytes.Buffer err := DefaultTemplates.ExecuteTemplate(&b, name+".html", data) @@ -60,48 +60,48 @@ func preparseWidget(widget *Widget, wdata string) (err error) { } sbytes := []byte(wdata) - widget.Literal = true + w.Literal = true // TODO: Split these hard-coded items out of this file and into the files for the individual widget types - switch widget.Type { + switch w.Type { case "simple", "about": var tmp NameTextPair err = json.Unmarshal(sbytes, &tmp) if err != nil { return err } - widget.Body, err = prebuildWidget("widget_"+widget.Type, tmp) + w.Body, err = prebuildWidget("widget_"+w.Type, tmp) case "search_and_filter": - widget.Literal = false - widget.BuildFunc = widgetSearchAndFilter + w.Literal = false + w.BuildFunc = widgetSearchAndFilter case "wol": - widget.Literal = false - widget.InitFunc = wolInit - widget.BuildFunc = wolRender - widget.TickFunc = wolTick + w.Literal = false + w.InitFunc = wolInit + w.BuildFunc = wolRender + w.TickFunc = wolTick case "wol_context": - widget.Literal = false - widget.BuildFunc = wolContextRender + w.Literal = false + w.BuildFunc = wolContextRender default: - widget.Body = wdata + w.Body = wdata } // TODO: Test this // TODO: Should we toss this through a proper parser rather than crudely replacing it? - widget.Location = strings.Replace(widget.Location, " ", "", -1) - widget.Location = strings.Replace(widget.Location, "frontend", "!panel", -1) - widget.Location = strings.Replace(widget.Location, "!!", "", -1) + w.Location = strings.Replace(w.Location, " ", "", -1) + w.Location = strings.Replace(w.Location, "frontend", "!panel", -1) + w.Location = strings.Replace(w.Location, "!!", "", -1) // Skip blank zones - var locs = strings.Split(widget.Location, "|") + locs := strings.Split(w.Location, "|") if len(locs) > 0 { - widget.Location = "" + w.Location = "" for _, loc := range locs { if loc == "" { continue } - widget.Location += loc + "|" + w.Location += loc + "|" } - widget.Location = widget.Location[:len(widget.Location)-1] + w.Location = w.Location[:len(w.Location)-1] } return err @@ -139,13 +139,13 @@ func HasDock(dock string) bool { } // TODO: Find a more optimimal way of doing this... -func HasWidgets(dock string, header *Header) bool { - if !header.Theme.HasDock(dock) { +func HasWidgets(dock string, h *Header) bool { + if !h.Theme.HasDock(dock) { return false } // Let themes forcibly override this slot - sbody := header.Theme.BuildDock(dock) + sbody := h.Theme.BuildDock(dock) if sbody != "" { return true } @@ -167,25 +167,24 @@ func HasWidgets(dock string, header *Header) bool { if !widget.Enabled { continue } - if widget.Allowed(header.Zone,header.ZoneID) { + if widget.Allowed(h.Zone, h.ZoneID) { wcount++ } } return wcount > 0 } -func BuildWidget(dock string, header *Header) (sbody string) { - var widgets []*Widget - if !header.Theme.HasDock(dock) { +func BuildWidget(dock string, h *Header) (sbody string) { + if !h.Theme.HasDock(dock) { return "" } - // Let themes forcibly override this slot - sbody = header.Theme.BuildDock(dock) + sbody = h.Theme.BuildDock(dock) if sbody != "" { return sbody } + var widgets []*Widget switch dock { case "leftOfNav": widgets = Docks.LeftOfNav @@ -195,7 +194,7 @@ func BuildWidget(dock string, header *Header) (sbody string) { // 1 = id for the default menu mhold, err := Menus.Get(1) if err == nil { - err := mhold.Build(header.Writer, &header.CurrentUser, header.Path) + err := mhold.Build(h.Writer, &h.CurrentUser, h.Path) if err != nil { LogError(err) } @@ -211,8 +210,8 @@ func BuildWidget(dock string, header *Header) (sbody string) { if !widget.Enabled { continue } - if widget.Allowed(header.Zone,header.ZoneID) { - item, err := widget.Build(header) + if widget.Allowed(h.Zone, h.ZoneID) { + item, err := widget.Build(h) if err != nil { LogError(err) } @@ -230,52 +229,46 @@ func getDockWidgets(dock string) (widgets []*Widget, err error) { defer rows.Close() for rows.Next() { - var widget = &Widget{Position: 0, Side: dock} - err = rows.Scan(&widget.ID, &widget.Position, &widget.Type, &widget.Enabled, &widget.Location, &widget.RawBody) + w := &Widget{Position: 0, Side: dock} + err = rows.Scan(&w.ID, &w.Position, &w.Type, &w.Enabled, &w.Location, &w.RawBody) if err != nil { return nil, err } - err = preparseWidget(widget, widget.RawBody) + err = preparseWidget(w, w.RawBody) if err != nil { return nil, err } - Widgets.set(widget) - widgets = append(widgets, widget) + Widgets.set(w) + widgets = append(widgets, w) } return widgets, rows.Err() } // TODO: Make a store for this? -func InitWidgets() error { - leftOfNavWidgets, err := getDockWidgets("leftOfNav") - if err != nil { - return err - } - rightOfNavWidgets, err := getDockWidgets("rightOfNav") - if err != nil { - return err - } - leftSidebarWidgets, err := getDockWidgets("leftSidebar") - if err != nil { - return err - } - rightSidebarWidgets, err := getDockWidgets("rightSidebar") - if err != nil { - return err - } - footerWidgets, err := getDockWidgets("footer") - if err != nil { - return err - } - +func InitWidgets() (fi error) { // TODO: Let themes set default values for widget docks, and let them lock in particular places with their stuff, e.g. leftOfNav and rightOfNav + f := func(name string) { + if fi != nil { + return + } + dock, err := getDockWidgets(name) + if err != nil { + fi = err + return + } + setDock(name, dock) + } + + f("leftOfNav") + f("rightOfNav") + f("leftSidebar") + f("rightSidebar") + f("footer") + if fi != nil { + return fi + } - setDock("leftOfNav", leftOfNavWidgets) - setDock("rightOfNav", rightOfNavWidgets) - setDock("leftSidebar", leftSidebarWidgets) - setDock("rightSidebar", rightSidebarWidgets) - setDock("footer", footerWidgets) AddScheduledSecondTask(Docks.LeftSidebar.Scheduler.Tick) AddScheduledSecondTask(Docks.RightSidebar.Scheduler.Tick) AddScheduledSecondTask(Docks.Footer.Scheduler.Tick) @@ -294,7 +287,6 @@ func releaseWidgets(widgets []*Widget) { // TODO: Use atomics func setDock(dock string, widgets []*Widget) { dockHandle := func(dockWidgets []*Widget) { - widgetUpdateMutex.Lock() DebugLog(dock, widgets) releaseWidgets(dockWidgets) } @@ -311,6 +303,8 @@ func setDock(dock string, widgets []*Widget) { dockWidgets.Scheduler.Store() return WidgetDock{widgets, dockWidgets.Scheduler} } + widgetUpdateMutex.Lock() + defer widgetUpdateMutex.Unlock() switch dock { case "leftOfNav": dockHandle(Docks.LeftOfNav) @@ -328,7 +322,6 @@ func setDock(dock string, widgets []*Widget) { fmt.Printf("bad dock '%s'\n", dock) return } - widgetUpdateMutex.Unlock() } type WidgetScheduler struct { @@ -336,8 +329,8 @@ type WidgetScheduler struct { store atomic.Value } -func (s *WidgetScheduler) Add(widget *Widget) { - s.widgets = append(s.widgets, widget) +func (s *WidgetScheduler) Add(w *Widget) { + s.widgets = append(s.widgets, w) } func (s *WidgetScheduler) Store() { diff --git a/misc_test.go b/misc_test.go index f5ac67a7..08d2139d 100644 --- a/misc_test.go +++ b/misc_test.go @@ -2,13 +2,13 @@ package main import ( "bytes" + "database/sql" "fmt" "net/http/httptest" "runtime/debug" "strconv" "testing" "time" - "database/sql" c "github.com/Azareal/Gosora/common" "github.com/Azareal/Gosora/common/phrases" @@ -183,7 +183,7 @@ func userStoreTest(t *testing.T, newUserID int) { expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) } - userList, _ = c.Users.BulkGetMap([]int{1,uid}) + userList, _ = c.Users.BulkGetMap([]int{1, uid}) expect(t, len(userList) == 2, fmt.Sprintf("Returned map should have two results, not %d", len(userList))) if ucache != nil { @@ -597,16 +597,16 @@ func TestForumStore(t *testing.T) { // Forum reload test, kind of hacky but gets the job done /* - CacheGet(id int) (*Forum, error) - CacheSet(forum *Forum) error + CacheGet(id int) (*Forum, error) + CacheSet(forum *Forum) error */ - expect(t,ok,"ForumCache should be available") + expect(t, ok, "ForumCache should be available") forum.Name = "nanana" fcache.CacheSet(forum) forum, err = c.Forums.Get(2) recordMustExist(t, err, "Couldn't find FID #2") expect(t, forum.Name == "nanana", fmt.Sprintf("The faux name should be nanana not %s", forum.Name)) - expectNilErr(t,c.Forums.Reload(2)) + expectNilErr(t, c.Forums.Reload(2)) forum, err = c.Forums.Get(2) recordMustExist(t, err, "Couldn't find FID #2") expect(t, forum.Name == "General", fmt.Sprintf("The proper name should be 2 not %s", forum.Name)) @@ -731,23 +731,23 @@ func TestForumPermsStore(t *testing.T) { } f := func(fid int, gid int, msg string, inv ...bool) { - fp, err := c.FPStore.Get(fid,gid) - expectNilErr(t,err) + fp, err := c.FPStore.Get(fid, gid) + expectNilErr(t, err) vt := fp.ViewTopic if len(inv) > 0 && inv[0] == true { vt = !vt } - expect(t,vt,msg) + expect(t, vt, msg) } initialState := func() { - f(1,1,"admins should be able to see reports") - f(1,2,"mods should be able to see reports") - f(1,3,"members should not be able to see reports",true) - f(1,4,"banned users should not be able to see reports",true) - f(2,1,"admins should be able to see general") - f(2,3,"members should be able to see general") - f(2,6,"guests should be able to see general") + f(1, 1, "admins should be able to see reports") + f(1, 2, "mods should be able to see reports") + f(1, 3, "members should not be able to see reports", true) + f(1, 4, "banned users should not be able to see reports", true) + f(2, 1, "admins should be able to see general") + f(2, 3, "members should be able to see general") + f(2, 6, "guests should be able to see general") } initialState() @@ -778,7 +778,7 @@ func TestGroupStore(t *testing.T) { group, err = c.Groups.Get(1) recordMustExist(t, err, "Couldn't find GID #1") expect(t, group.ID == 1, fmt.Sprintf("group.ID doesn't not match the requested GID. Got '%d' instead.'", group.ID)) - expect(t,len(group.CanSee) > 0,"group.CanSee should not be zero") + expect(t, len(group.CanSee) > 0, "group.CanSee should not be zero") expect(t, !c.Groups.Exists(-1), "GID #-1 shouldn't exist") // 0 aka Unknown, for system posts and other oddities @@ -889,7 +889,7 @@ func TestGroupStore(t *testing.T) { return true } - expect(t, canSeeTest(group.CanSee,canSee), "group.CanSee is not being reused") + expect(t, canSeeTest(group.CanSee, canSee), "group.CanSee is not being reused") // TODO: Test group deletion // TODO: Test group reload @@ -1030,7 +1030,7 @@ func TestProfileReplyStore(t *testing.T) { func TestActivityStream(t *testing.T) { miscinit(t) - expect(t,c.Activity.Count()==0,"activity stream count should be 0") + expect(t, c.Activity.Count() == 0, "activity stream count should be 0") _, err := c.Activity.Get(-1) recordMustNotExist(t, err, "activity item -1 shouldn't exist") @@ -1041,17 +1041,17 @@ func TestActivityStream(t *testing.T) { a := c.Alert{ActorID: 1, TargetUserID: 1, Event: "like", ElementType: "topic", ElementID: 1} id, err := c.Activity.Add(a) - expectNilErr(t,err) - expect(t,id==1,"new activity item id should be 1") + expectNilErr(t, err) + expect(t, id == 1, "new activity item id should be 1") - expect(t,c.Activity.Count()==1,"activity stream count should be 1") + expect(t, c.Activity.Count() == 1, "activity stream count should be 1") alert, err := c.Activity.Get(1) - expectNilErr(t,err) - expect(t,alert.ActorID==1,"alert actorid should be 1") - expect(t,alert.TargetUserID==1,"alert targetuserid should be 1") - expect(t,alert.Event=="like","alert event type should be like") - expect(t,alert.ElementType=="topic","alert element type should be topic") - expect(t,alert.ElementID==1,"alert element id should be 1") + expectNilErr(t, err) + expect(t, alert.ActorID == 1, "alert actorid should be 1") + expect(t, alert.TargetUserID == 1, "alert targetuserid should be 1") + expect(t, alert.Event == "like", "alert event type should be like") + expect(t, alert.ElementType == "topic", "alert element type should be topic") + expect(t, alert.ElementID == 1, "alert element id should be 1") } func TestLogs(t *testing.T) { @@ -1217,35 +1217,41 @@ func TestPluginManager(t *testing.T) { expectNilErr(t, plugin.SetActive(false)) // Hook tests - expect(t, c.GetHookTable().Sshook("haha", "ho") == "ho", "Sshook shouldn't have anything bound to it yet") + ht := func() *c.HookTable { + return c.GetHookTable() + } + expect(t, ht().Sshook("haha", "ho") == "ho", "Sshook shouldn't have anything bound to it yet") handle := func(in string) (out string) { return in + "hi" } plugin.AddHook("haha", handle) - expect(t, c.GetHookTable().Sshook("haha", "ho") == "hohi", "Sshook didn't give hohi") + expect(t, ht().Sshook("haha", "ho") == "hohi", "Sshook didn't give hohi") plugin.RemoveHook("haha", handle) - expect(t, c.GetHookTable().Sshook("haha", "ho") == "ho", "Sshook shouldn't have anything bound to it anymore") + expect(t, ht().Sshook("haha", "ho") == "ho", "Sshook shouldn't have anything bound to it anymore") - expect(t, c.GetHookTable().Hook("haha", "ho") == "ho", "Hook shouldn't have anything bound to it yet") + expect(t, ht().Hook("haha", "ho") == "ho", "Hook shouldn't have anything bound to it yet") handle2 := func(inI interface{}) (out interface{}) { return inI.(string) + "hi" } plugin.AddHook("hehe", handle2) - expect(t, c.GetHookTable().Hook("hehe", "ho").(string) == "hohi", "Hook didn't give hohi") + expect(t, ht().Hook("hehe", "ho").(string) == "hohi", "Hook didn't give hohi") plugin.RemoveHook("hehe", handle2) - expect(t, c.GetHookTable().Hook("hehe", "ho").(string) == "ho", "Hook shouldn't have anything bound to it anymore") + expect(t, ht().Hook("hehe", "ho").(string) == "ho", "Hook shouldn't have anything bound to it anymore") // TODO: Add tests for more hook types } func TestPhrases(t *testing.T) { + getPhrase := phrases.GetGlobalPermPhrase tp := func(name string, expects string) { - expect(t, phrases.GetGlobalPermPhrase(name) == expects, "Not the expected phrase") + res := getPhrase(name) + expect(t, res == expects, "Not the expected phrase, got '"+res+"' instead") } - tp("BanUsers","Can ban users") - tp("NoSuchPerm","{lang.perms[NoSuchPerm]}") - tp("ViewTopic","Can view topics") - tp("NoSuchPerm","{lang.perms[NoSuchPerm]}") + tp("BanUsers", "Can ban users") + tp("NoSuchPerm", "{lang.perms[NoSuchPerm]}") + getPhrase = phrases.GetLocalPermPhrase + tp("ViewTopic", "Can view topics") + tp("NoSuchPerm", "{lang.perms[NoSuchPerm]}") // TODO: Cover the other phrase types, also try switching between languages to see if anything strange happens } diff --git a/parser_test.go b/parser_test.go index ed678afd..f2cdc362 100644 --- a/parser_test.go +++ b/parser_test.go @@ -143,6 +143,7 @@ func TestParser(t *testing.T) { l := &METriList{nil} url := "github.com/Azareal/Gosora" + eurl := "//" + url + "" l.Add("", "") l.Add("haha", "haha") l.Add("t", "t") @@ -183,7 +184,7 @@ func TestParser(t *testing.T) { l.Add("gi", "gi") l.Add("ss", "ss") l.Add("haha\nhaha\nhaha", "haha
haha
haha") - l.Add("//"+url, "//"+url+"") + l.Add("//"+url, eurl) l.Add("//a", "//a") l.Add(" //a", " //a") l.Add("//a ", "//a ") @@ -191,16 +192,16 @@ func TestParser(t *testing.T) { l.Add("d //a ", "d //a ") l.Add("ddd ddd //a ", "ddd ddd //a ") l.Add("https://"+url, "https://"+url+"") - l.Add("https://t", "https://t") - l.Add("http://"+url, "http://"+url+"") + l.Add("https://t", "https://t") + l.Add("http://"+url, "http://"+url+"") l.Add("#http://"+url, "#http://"+url) l.Add("@http://"+url, "[Invalid Profile]ttp://"+url) - l.Add("//"+url+"\n", "//"+url+"
") - l.Add("\n//"+url, "
//"+url+"") - l.Add("\n//"+url+"\n", "
//"+url+"
") - l.Add("\n//"+url+"\n\n", "
//"+url+"

") - l.Add("//"+url+"\n//"+url, "//"+url+"
//"+url+"") - l.Add("//"+url+"\n\n//"+url, "//"+url+"

//"+url+"") + l.Add("//"+url+"\n", "//"+url+"
") + l.Add("\n//"+url, "
"+eurl) + l.Add("\n//"+url+"\n", "
"+eurl+"
") + l.Add("\n//"+url+"\n\n", "
"+eurl+"

") + l.Add("//"+url+"\n//"+url, eurl+"
"+eurl) + l.Add("//"+url+"\n\n//"+url, eurl+"

"+eurl) l.Add("//"+c.Site.URL, "//"+c.Site.URL+"") l.Add("//"+c.Site.URL+"\n", "//"+c.Site.URL+"
") l.Add("//"+c.Site.URL+"\n//"+c.Site.URL, "//"+c.Site.URL+"
//"+c.Site.URL+"") @@ -214,24 +215,24 @@ func TestParser(t *testing.T) { local("127.0.0.1") local("[::1]") - l.Add("https://www.youtube.com/watch?v=lalalalala","") + 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("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("#tid-1", "#tid-1") @@ -242,8 +243,8 @@ func TestParser(t *testing.T) { l.Add("@ #tid-@", "[Invalid Profile]#tid-@") l.Add("#tid-1 #tid-1", "#tid-1 #tid-1") l.Add("#tid-0", "[Invalid Topic]") - l.Add("https://"+url+"/#tid-1", "https://"+url+"/#tid-1") - l.Add("https://"+url+"/?hi=2", "https://"+url+"/?hi=2") + l.Add("https://"+url+"/#tid-1", "https://"+url+"/#tid-1") + l.Add("https://"+url+"/?hi=2", "https://"+url+"/?hi=2") l.Add("#fid-1", "#fid-1") l.Add(" #fid-1", " #fid-1") l.Add("#fid-0", "[Invalid Forum]") diff --git a/plugin_bbcode.go b/plugin_bbcode.go index 1fa6a0bb..96f1aceb 100644 --- a/plugin_bbcode.go +++ b/plugin_bbcode.go @@ -60,8 +60,8 @@ func bbcodeRegexParse(msg string) string { msg = bbcodeItalic.ReplaceAllString(msg, "$1") msg = bbcodeUnderline.ReplaceAllString(msg, "$1") msg = bbcodeStrike.ReplaceAllString(msg, "$1") - msg = bbcodeURL.ReplaceAllString(msg, "$1$2//$3") - msg = bbcodeURLLabel.ReplaceAllString(msg, "$4") + msg = bbcodeURL.ReplaceAllString(msg, "$1$2//$3") + msg = bbcodeURLLabel.ReplaceAllString(msg, "$4") msg = bbcodeQuotes.ReplaceAllString(msg, "
$1
") msg = bbcodeH1.ReplaceAllString(msg, "

$1

") //msg = bbcodeCode.ReplaceAllString(msg,"$1") @@ -198,8 +198,8 @@ func bbcodeParseWithoutCode(msg string) string { // Copy the new complex parser over once the rough edges have been smoothed over if complexBbc { msg = string(msgbytes) - msg = bbcodeURL.ReplaceAllString(msg, "
$1$2//$3") - msg = bbcodeURLLabel.ReplaceAllString(msg, "$4") + msg = bbcodeURL.ReplaceAllString(msg, "$1$2//$3") + msg = bbcodeURLLabel.ReplaceAllString(msg, "$4") msg = bbcodeQuotes.ReplaceAllString(msg, "
$1
") return bbcodeCode.ReplaceAllString(msg, "$1") } @@ -325,8 +325,8 @@ func bbcodeFullParse(msg string) string { } // TODO: Optimise these - //msg = bbcode_url.ReplaceAllString(msg,"
$1$2//$3") - msg = bbcodeURLLabel.ReplaceAllString(msg, "$4") + //msg = bbcode_url.ReplaceAllString(msg,"$1$2//$3") + msg = bbcodeURLLabel.ReplaceAllString(msg, "$4") msg = bbcodeQuotes.ReplaceAllString(msg, "
$1
") msg = bbcodeCode.ReplaceAllString(msg, "$1") msg = bbcodeH1.ReplaceAllString(msg, "

$1

")