diff --git a/common/parser.go b/common/parser.go
index bbddb4ff..40e47b7a 100644
--- a/common/parser.go
+++ b/common/parser.go
@@ -16,6 +16,7 @@ import (
// TODO: Somehow localise these?
var SpaceGap = []byte(" ")
var httpProtBytes = []byte("http://")
+var DoubleForwardSlash = []byte("//")
var InvalidURL = []byte("[Invalid URL]")
var InvalidTopic = []byte("[Invalid Topic]")
var InvalidProfile = []byte("[Invalid Profile]")
@@ -531,7 +532,8 @@ func ParseMessage(msg string, sectionID int, sectionType string /*, user User*/)
sb.Write(bytesSinglequote)
sb.Write(urlMention)
sb.Write(bytesGreaterthan)
- sb.WriteString("@" + menUser.Name)
+ sb.WriteByte('@')
+ sb.WriteString(menUser.Name)
sb.Write(URLClose)
lastItem = i
i--
@@ -560,11 +562,22 @@ func ParseMessage(msg string, sectionID int, sectionType string /*, user User*/)
urlLen, ok := PartialURLStringLen(msg[i:])
if len(msg) < i+urlLen {
//fmt.Println("o1")
- sb.Write(InvalidURL)
+ if urlLen == 2 {
+ sb.Write(DoubleForwardSlash)
+ } else {
+ sb.Write(InvalidURL)
+ }
i += len(msg) - 1
lastItem = i
break
}
+ if urlLen == 2 {
+ sb.Write(DoubleForwardSlash)
+ i += urlLen
+ lastItem = i
+ i--
+ continue
+ }
//fmt.Println("msg[i:i+urlLen]:", "'"+msg[i:i+urlLen]+"'")
if !ok {
//fmt.Printf("o2: i = %d; i+urlLen = %d\n",i,i+urlLen)
diff --git a/parser_test.go b/parser_test.go
index 21d88a54..20b601e3 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -145,22 +145,23 @@ func TestParser(t *testing.T) {
msgList.Add("", "")
msgList.Add("haha", "haha")
msgList.Add("t", "t")
- msgList.Add("//", "[Invalid URL]")
+ msgList.Add("//", "//")
msgList.Add("http://", "[Invalid URL]")
msgList.Add("https://", "[Invalid URL]")
msgList.Add("ftp://", "[Invalid URL]")
msgList.Add("git://", "[Invalid URL]")
msgList.Add("ssh://", "ssh://")
- msgList.Add("// ", "[Invalid URL] ")
- msgList.Add("// //", "[Invalid URL] [Invalid URL]")
+ msgList.Add("// ", "// ")
+ msgList.Add("// //", "// //")
+ msgList.Add("// // //", "// // //")
msgList.Add("http:// ", "[Invalid URL] ")
msgList.Add("https:// ", "[Invalid URL] ")
msgList.Add("ftp:// ", "[Invalid URL] ")
msgList.Add("git:// ", "[Invalid URL] ")
msgList.Add("ssh:// ", "ssh:// ")
- msgList.Add("// t", "[Invalid URL] t")
+ msgList.Add("// t", "// t")
msgList.Add("http:// t", "[Invalid URL] t")
msgList.Add("http:", "http:")
@@ -183,6 +184,11 @@ func TestParser(t *testing.T) {
msgList.Add("haha\nhaha\nhaha", "haha
haha
haha")
msgList.Add("//"+url, "//"+url+"")
msgList.Add("//a", "//a")
+ msgList.Add(" //a", " //a")
+ msgList.Add("//a ", "//a ")
+ msgList.Add(" //a ", " //a ")
+ msgList.Add("d //a ", "d //a ")
+ msgList.Add("ddd ddd //a ", "ddd ddd //a ")
msgList.Add("https://"+url, "https://"+url+"")
msgList.Add("https://t", "https://t")
msgList.Add("http://"+url, "http://"+url+"")