@@ -67,6 +67,68 @@ func TestMisc_IsSameDomain(t *testing.T) {
67
67
assert .False (t , IsSameDomain ("favicon.ico" ))
68
68
}
69
69
70
+ func TestRender_links (t * testing.T ) {
71
+ setting .AppURL = AppURL
72
+ setting .AppSubURL = AppSubURL
73
+
74
+ test := func (input , expected string ) {
75
+ buffer := RenderString ("a.md" , input , setting .AppSubURL , nil )
76
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (buffer )))
77
+ }
78
+ // Text that should be turned into URL
79
+
80
+ test (
81
+ "https://www.example.com" ,
82
+ `<p><a href="https://www.example.com" rel="nofollow">https://www.example.com</a></p>` )
83
+ test (
84
+ "http://www.example.com" ,
85
+ `<p><a href="http://www.example.com" rel="nofollow">http://www.example.com</a></p>` )
86
+ test (
87
+ "https://example.com" ,
88
+ `<p><a href="https://example.com" rel="nofollow">https://example.com</a></p>` )
89
+ test (
90
+ "http://example.com" ,
91
+ `<p><a href="http://example.com" rel="nofollow">http://example.com</a></p>` )
92
+ test (
93
+ "http://foo.com/blah_blah" ,
94
+ `<p><a href="http://foo.com/blah_blah" rel="nofollow">http://foo.com/blah_blah</a></p>` )
95
+ test (
96
+ "http://foo.com/blah_blah/" ,
97
+ `<p><a href="http://foo.com/blah_blah/" rel="nofollow">http://foo.com/blah_blah/</a></p>` )
98
+ test (
99
+ "http://www.example.com/wpstyle/?p=364" ,
100
+ `<p><a href="http://www.example.com/wpstyle/?p=364" rel="nofollow">http://www.example.com/wpstyle/?p=364</a></p>` )
101
+ test (
102
+ "https://www.example.com/foo/?bar=baz&inga=42&quux" ,
103
+ `<p><a href="https://www.example.com/foo/?bar=baz&inga=42&quux" rel="nofollow">https://www.example.com/foo/?bar=baz&inga=42&quux</a></p>` )
104
+ test (
105
+ "http://142.42.1.1/" ,
106
+ `<p><a href="http://142.42.1.1/" rel="nofollow">http://142.42.1.1/</a></p>` )
107
+
108
+ // Test that should *not* be turned into URL
109
+ test (
110
+ "www.example.com" ,
111
+ `<p>www.example.com</p>` )
112
+ test (
113
+ "example.com" ,
114
+ `<p>example.com</p>` )
115
+ test (
116
+ "test.example.com" ,
117
+ `<p>test.example.com</p>` )
118
+ test (
119
+ "http://" ,
120
+ `<p>http://</p>` )
121
+ test (
122
+ "https://" ,
123
+ `<p>https://</p>` )
124
+ test (
125
+ "://" ,
126
+ `<p>://</p>` )
127
+ test (
128
+ "www" ,
129
+ `<p>www</p>` )
130
+ }
131
+
70
132
func TestRender_ShortLinks (t * testing.T ) {
71
133
setting .AppURL = AppURL
72
134
setting .AppSubURL = AppSubURL
0 commit comments