ts3server://example.com?port=9000
`, // }, "valid-link-5": { Markdown: `www.example.com`, ExpectedHTML: ``, }, "valid-link-6": { Markdown: `www.example.com/index`, ExpectedHTML: ``, }, "valid-link-7": { Markdown: `www.example.com/index.html`, ExpectedHTML: ``, }, "valid-link-8": { Markdown: `http://example.com/index/sub`, ExpectedHTML: ``, }, "valid-link-9": { Markdown: `www1.example.com`, ExpectedHTML: ``, }, "valid-link-10": { Markdown: `https://en.wikipedia.org/wiki/URLs#Syntax`, ExpectedHTML: `https://en.wikipedia.org/wiki/URLs#Syntax
`, }, "valid-link-11": { Markdown: `https://groups.google.com/forum/#!msg`, ExpectedHTML: `https://groups.google.com/forum/#!msg
`, }, "valid-link-12": { Markdown: `www.example.com/index?params=1`, ExpectedHTML: `www.example.com/index?params=1
`, }, "valid-link-13": { Markdown: `www.example.com/index?params=1&other=2`, ExpectedHTML: `www.example.com/index?params=1&other=2
`, }, "valid-link-14": { Markdown: `www.example.com/index?params=1;other=2`, ExpectedHTML: `www.example.com/index?params=1;other=2
`, }, "valid-link-15": { Markdown: `http://www.example.com/_/page`, ExpectedHTML: ``, }, "valid-link-16": { Markdown: `https://en.wikipedia.org/wiki/🐬`, ExpectedHTML: `https://en.wikipedia.org/wiki/🐬
`, }, "valid-link-17": { Markdown: `http://✪df.ws/1234`, ExpectedHTML: ``, }, "valid-link-18": { Markdown: `https://groups.google.com/forum/#!msg`, ExpectedHTML: `https://groups.google.com/forum/#!msg
`, }, "valid-link-19": { Markdown: `https://пример.срб/пример-26/`, ExpectedHTML: ``, }, "valid-link-20": { Markdown: `mailto://test@example.com`, ExpectedHTML: ``, }, "valid-link-21": { Markdown: `tel://555-123-4567`, ExpectedHTML: ``, }, "ip-address-1": { Markdown: `http://127.0.0.1`, ExpectedHTML: ``, }, "ip-address-2": { Markdown: `http://192.168.1.1:4040`, ExpectedHTML: ``, }, "ip-address-3": { Markdown: `http://username:password@127.0.0.1`, ExpectedHTML: `http://username:password@127.0.0.1
`, }, "ip-address-4": { Markdown: `http://username:password@[2001:0:5ef5:79fb:303a:62d5:3312:ff42]:80`, ExpectedHTML: `http://username:password@[2001:0:5ef5:79fb:303a:62d5:3312:ff42]:80
`, }, "link-with-brackets-1": { Markdown: `https://en.wikipedia.org/wiki/Rendering_(computer_graphics)`, ExpectedHTML: `https://en.wikipedia.org/wiki/Rendering_(computer_graphics)
`, }, "link-with-brackets-2": { Markdown: `http://example.com/more_(than)_one_(parens)`, ExpectedHTML: `http://example.com/more_(than)_one_(parens)
`, }, "link-with-brackets-3": { Markdown: `http://example.com/(something)?after=parens`, ExpectedHTML: `http://example.com/(something)?after=parens
`, }, "link-with-brackets-4": { Markdown: `http://foo.com/unicode_(✪)_in_parens`, ExpectedHTML: `http://foo.com/unicode_(✪)_in_parens
`, }, "inside-another-link-1": { Markdown: `[www.example.com](https://example.com)`, ExpectedHTML: ``, }, "inside-another-link-2": { Markdown: `[http://www.example.com](https://example.com)`, ExpectedHTML: ``, }, "link-in-sentence-1": { Markdown: `(http://example.com)`, ExpectedHTML: ``, }, "link-in-sentence-2": { Markdown: `(see http://example.com)`, ExpectedHTML: `(see http://example.com)
`, }, "link-in-sentence-3": { Markdown: `(http://example.com watch this)`, ExpectedHTML: `(http://example.com watch this)
`, }, "link-in-sentence-4": { Markdown: `This is a sentence with a http://example.com in it.`, ExpectedHTML: `This is a sentence with a http://example.com in it.
`, }, "link-in-sentence-5": { Markdown: `This is a sentence with a [link](http://example.com) in it.`, ExpectedHTML: `This is a sentence with a link in it.
`, }, "link-in-sentence-6": { Markdown: `This is a sentence with a http://example.com/_/underscore in it.`, ExpectedHTML: `This is a sentence with a http://example.com/_/underscore in it.
`, }, "link-in-sentence-7": { Markdown: `This is a sentence with a link (http://example.com) in it.`, ExpectedHTML: `This is a sentence with a link (http://example.com) in it.
`, }, "link-in-sentence-8": { Markdown: `This is a sentence with a (https://en.wikipedia.org/wiki/Rendering_(computer_graphics)) in it.`, ExpectedHTML: `This is a sentence with a (https://en.wikipedia.org/wiki/Rendering_(computer_graphics)) in it.
`, }, "link-in-sentence-9": { Markdown: `This is a sentence with a http://192.168.1.1:4040 in it.`, ExpectedHTML: `This is a sentence with a http://192.168.1.1:4040 in it.
`, }, "link-in-sentence-10": { Markdown: `This is a link to http://example.com.`, ExpectedHTML: `This is a link to http://example.com.
`, }, "link-in-sentence-11": { Markdown: `This is a link to http://example.com*`, ExpectedHTML: `This is a link to http://example.com*
`, }, "link-in-sentence-12": { Markdown: `This is a link to http://example.com_`, ExpectedHTML: `This is a link to http://example.com_
`, }, "link-in-sentence-13": { Markdown: `This is a link containing http://example.com/something?with,commas,in,url, but not at the end`, ExpectedHTML: `This is a link containing http://example.com/something?with,commas,in,url, but not at the end
`, }, "link-in-sentence-14": { Markdown: `This is a question about a link http://example.com?`, ExpectedHTML: `This is a question about a link http://example.com?
`, }, "plt-7250-link-with-trailing-periods-1": { Markdown: `http://example.com.`, ExpectedHTML: ``, }, "plt-7250-link-with-trailing-periods-2": { Markdown: `http://example.com...`, ExpectedHTML: ``, }, "plt-7250-link-with-trailing-periods-3": { Markdown: `http://example.com/foo.`, ExpectedHTML: ``, }, "plt-7250-link-with-trailing-periods-4": { Markdown: `http://example.com/foo...`, ExpectedHTML: ``, }, "plt-7250-link-with-trailing-periods-5": { Markdown: `http://example.com/foo.bar`, ExpectedHTML: ``, }, "plt-7250-link-with-trailing-periods-6": { Markdown: `http://example.com/foo...bar`, ExpectedHTML: ``, }, "rn-319-www-link-as-part-of-word-1": { Markdown: `testwww.example.com`, ExpectedHTML: `testwww.example.com
`, }, "mm-10180-link-containing-period-followed-by-non-letter-1": { Markdown: `https://example.com/123.+Pagetitle`, ExpectedHTML: `https://example.com/123.+Pagetitle
`, }, "mm-10180-link-containing-period-followed-by-non-letter-2": { Markdown: `https://example.com/123.?Pagetitle`, ExpectedHTML: `https://example.com/123.?Pagetitle
`, }, "mm-10180-link-containing-period-followed-by-non-letter-3": { Markdown: `https://example.com/123.-Pagetitle`, ExpectedHTML: `https://example.com/123.-Pagetitle
`, }, "mm-10180-link-containing-period-followed-by-non-letter-4": { Markdown: `https://example.com/123._Pagetitle`, ExpectedHTML: ``, }, "mm-10180-link-containing-period-followed-by-non-letter-5": { Markdown: `https://example.com/123.+`, ExpectedHTML: ``, }, "mm-10180-link-containing-period-followed-by-non-letter-6": { Markdown: `https://example.com/123.?`, ExpectedHTML: ``, }, "mm-10180-link-containing-period-followed-by-non-letter-7": { Markdown: `https://example.com/123.-`, ExpectedHTML: ``, }, "mm-10180-link-containing-period-followed-by-non-letter-8": { Markdown: `https://example.com/123._`, ExpectedHTML: ``, }, } { t.Run(name, func(t *testing.T) { assert.Equal(t, tc.ExpectedHTML, RenderHTML(tc.Markdown)) }) } } func Test_isAllowedBeforeWWWLink(t *testing.T) { type args struct { c byte } tests := []struct { name string args args want bool }{ { name: "empty space", args: args{ c: byte(' '), }, want: false, }, { name: "asterisk", args: args{ c: byte('*'), }, want: true, }, { name: "underscore", args: args{ c: byte('_'), }, want: true, }, { name: "open parenthesis", args: args{ c: byte('('), }, want: true, }, { name: "close parenthesis", args: args{ c: byte(')'), }, want: true, }, { name: "tilde", args: args{ c: byte('~'), }, want: true, }, { name: "open angle bracket", args: args{ c: byte('<'), }, want: true, }, { name: "close angle bracket", args: args{ c: byte('>'), }, want: true, }, { name: "alphabet", args: args{ c: byte('c'), }, want: false, }, { name: "number", args: args{ c: byte('4'), }, want: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert.Equalf(t, tt.want, isAllowedBeforeWWWLink(tt.args.c), "isAllowedBeforeWWWLink(%v)", tt.args.c) }) } }