1
2
3
4
5
6
7
8
9
10
11
12
13
14 import unittest
15
16 from trac.util.datefmt import datetime_now, utc
17 from trac.wiki.model import WikiPage
18 from trac.wiki.tests import formatter
19
20
21 TEST_CASES = u"""
22 ============================== wiki: link resolver
23 wiki:TestPage
24 wiki:TestPage/
25 wiki:/TestPage
26 [wiki:/TestPage]
27 [wiki:/TestPage ]
28 [wiki:/TestPage\u200B]
29 [wiki:/TestPage /TestPage]
30 wiki:"Space 1 23"
31 wiki:"C'est l'\xe9t\xe9"
32 wiki:MissingPage
33 wiki:12
34 wiki:abc
35 ------------------------------
36 <p>
37 <a class="wiki" href="/wiki/TestPage">wiki:TestPage</a>
38 <a class="wiki" href="/wiki/TestPage">wiki:TestPage/</a>
39 <a class="wiki" href="/wiki/TestPage">wiki:/TestPage</a>
40 <a class="wiki" href="/wiki/TestPage">TestPage</a>
41 <a class="wiki" href="/wiki/TestPage">TestPage</a>
42 <a class="wiki" href="/wiki/TestPage">TestPage</a>
43 <a class="wiki" href="/wiki/TestPage">/TestPage</a>
44 <a class="wiki" href="/wiki/Space%201%2023">wiki:"Space 1 23"</a>
45 <a class="wiki" href="/wiki/C'est%20l'%C3%A9t%C3%A9">wiki:"C'est l'\xe9t\xe9"</a>
46 <a class="missing wiki" href="/wiki/MissingPage" rel="nofollow">wiki:MissingPage?</a>
47 <a class="missing wiki" href="/wiki/12" rel="nofollow">wiki:12?</a>
48 <a class="missing wiki" href="/wiki/abc" rel="nofollow">wiki:abc?</a>
49 </p>
50 ------------------------------
51 ============================== wiki: link resolver + query and fragment
52 wiki:TestPage?format=txt
53 wiki:TestPage/?version=12
54 wiki:TestPage/?action=diff&version=12
55 wiki:"Space 1 23#heading"
56 ------------------------------
57 <p>
58 <a class="wiki" href="/wiki/TestPage?format=txt">wiki:TestPage?format=txt</a>
59 <a class="wiki" href="/wiki/TestPage?version=12">wiki:TestPage/?version=12</a>
60 <a class="wiki" href="/wiki/TestPage?action=diff&version=12">wiki:TestPage/?action=diff&version=12</a>
61 <a class="wiki" href="/wiki/Space%201%2023#heading">wiki:"Space 1 23#heading"</a>
62 </p>
63 ------------------------------
64 ============================== WikiPageNames conformance
65 CamelCase AlabamA ABc AlaBamA FooBar
66 ------------------------------
67 <p>
68 <a class="missing wiki" href="/wiki/CamelCase" rel="nofollow">CamelCase?</a> AlabamA ABc AlaBamA <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>
69 </p>
70 ------------------------------
71 ============================== WikiPageNames conformance (unicode)
72 SmÅogstore should produce a link
73 and so should wiki:ÜberflüssigkeitsTheorie
74 ------------------------------
75 <p>
76 <a class="missing wiki" href="/wiki/Sm%C3%85ogstore" rel="nofollow">SmÅogstore?</a> should produce a link
77 and so should <a class="missing wiki" href="/wiki/%C3%9Cberfl%C3%BCssigkeitsTheorie" rel="nofollow">wiki:ÜberflüssigkeitsTheorie?</a>
78 </p>
79 ------------------------------
80 ============================== More WikiPageNames conformance
81 CamelCase,CamelCase.CamelCase: CamelCase
82 But not CamelCase2
83 nor CamelCase_
84 ------------------------------
85 <p>
86 <a class="missing wiki" href="/wiki/CamelCase" rel="nofollow">CamelCase?</a>,<a class="missing wiki" href="/wiki/CamelCase" rel="nofollow">CamelCase?</a>.<a class="missing wiki" href="/wiki/CamelCase" rel="nofollow">CamelCase?</a>: <a class="missing wiki" href="/wiki/CamelCase" rel="nofollow">CamelCase?</a>
87 But not CamelCase2
88 nor CamelCase_
89 </p>
90 ------------------------------
91 ============================== Escaping WikiPageNames
92 !CamelCase
93 ------------------------------
94 <p>
95 CamelCase
96 </p>
97 ------------------------------
98 ============================== WikiPageNames endings
99 foo (FooBar )
100 foo FooBar: something
101 foo FooBar.
102 FooBar, foo
103 foo FooBar;
104 foo FooBar!
105 foo FooBar?
106 foo (FooBar)
107 foo {FooBar}
108 foo 'FooBar'
109 foo "FooBar"
110 foo [FooBar]
111 ------------------------------
112 <p>
113 foo (<a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a> )
114 foo <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>: something
115 foo <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>.
116 <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>, foo
117 foo <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>;
118 foo <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>!
119 foo <a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>?
120 foo (<a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>)
121 foo {<a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>}
122 foo '<a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>'
123 foo "<a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>"
124 foo [<a class="missing wiki" href="/wiki/FooBar" rel="nofollow">FooBar?</a>]
125 </p>
126 ------------------------------
127 ============================== WikiPageNames counter examples
128 A0B1, ST62T53C6, IR32V1H000
129 ------------------------------
130 <p>
131 A0B1, ST62T53C6, IR32V1H000
132 </p>
133 ------------------------------
134 ============================== WikiPageNames with fragment identifier
135 SandBox#heading-fixed-id
136
137 wiki:TracSubversion#TracandSubversion1.3.1. etc.
138 TracSubversion#TracandSubversion1.3.1. etc.
139 ------------------------------
140 <p>
141 <a class="missing wiki" href="/wiki/SandBox#heading-fixed-id" rel="nofollow">SandBox#heading-fixed-id?</a>
142 </p>
143 <p>
144 <a class="missing wiki" href="/wiki/TracSubversion#TracandSubversion1.3.1" rel="nofollow">wiki:TracSubversion#TracandSubversion1.3.1?</a>. etc.
145 <a class="missing wiki" href="/wiki/TracSubversion#TracandSubversion1.3.1" rel="nofollow">TracSubversion#TracandSubversion1.3.1?</a>. etc.
146 </p>
147 ------------------------------
148 ============================== WikiPageNames with fragment id (performance test)
149 BillOfMaterials#get_bill_of_materials_from_room_xml(fpxml=nil)
150
151 [BillOfMaterials#get_bill_of_materials_from_room_xml(fpxml=nil)]
152
153 [BillOfMaterials#get_bill_of_materials_from_room_xml(fpxml=nil) speed]
154 ------------------------------
155 <p>
156 <a class="missing wiki" href="/wiki/BillOfMaterials#get_bill_of_materials_from_room_xml" rel="nofollow">BillOfMaterials#get_bill_of_materials_from_room_xml?</a>(fpxml=nil)
157 </p>
158 <p>
159 [<a class="missing wiki" href="/wiki/BillOfMaterials#get_bill_of_materials_from_room_xml" rel="nofollow">BillOfMaterials#get_bill_of_materials_from_room_xml?</a>(fpxml=nil)]
160 </p>
161 <p>
162 [<a class="missing wiki" href="/wiki/BillOfMaterials#get_bill_of_materials_from_room_xml" rel="nofollow">BillOfMaterials#get_bill_of_materials_from_room_xml?</a>(fpxml=nil) speed]
163 </p>
164 ------------------------------
165 ============================== WikiPageNames counter examples (paths)
166 /absolute/path/is/NotWiki and relative/path/is/NotWiki and ../higher/is/NotWiki
167 but ThisIs/SubWiki and now This/Also
168 and ../Relative/Camel or /Absolute/Camel as well
169 ------------------------------
170 <p>
171 /absolute/path/is/NotWiki and relative/path/is/NotWiki and ../higher/is/NotWiki
172 but <a class="missing wiki" href="/wiki/ThisIs/SubWiki" rel="nofollow">ThisIs/SubWiki?</a> and now <a class="missing wiki" href="/wiki/This/Also" rel="nofollow">This/Also?</a>
173 and <a class="missing wiki" href="/wiki/Relative/Camel" rel="nofollow">../Relative/Camel?</a> or <a class="missing wiki" href="/wiki/Absolute/Camel" rel="nofollow">/Absolute/Camel?</a> as well
174 </p>
175 ------------------------------
176 ============================== WikiPageNames counter examples (numbers)
177 8FjBpOmy
178 anotherWikiPageName
179 ------------------------------
180 <p>
181 8FjBpOmy
182 anotherWikiPageName
183 </p>
184 ------------------------------
185 8FjBpOmy
186 anotherWikiPageName
187 ============================== WikiPageNames counter examples (unicode)
188 Småbokstaver should not produce a link
189 neither should AbAbÅ nor AbAbÅÅb
190 ------------------------------
191 <p>
192 Småbokstaver should not produce a link
193 neither should AbAbÅ nor AbAbÅÅb
194 </p>
195 ------------------------------
196 Småbokstaver should not produce a link
197 neither should AbAbÅ nor AbAbÅÅb
198 ============================== not a WikiPageNames at all (#9025 regression)
199 [ሀሁሂሃሄህሆለሉሊላሌልሎሏሐሑሒሓሔሕሖመሙሚማሜምሞሟሠሡሢሣሤሥሦረሩሪራሬርሮሯሰሱሲሳሴስሶሷሸሹሺሻሼሽሾሿቀቁቂቃቄቅቆቈቊቋቌቍቐቑቒቓቔቕቖቘቚቛቜቝበቡቢባቤብቦቧቨቩቪቫቬቭቮቯተቱቲታቴትቶቷቸቹቺቻቼችቾቿኀኁኂኃኄኅኆኈኊኋኌኍነኑኒናኔንኖኗኘኙኚኛኜኝኞኟአኡኢኣኤእኦኧከኩኪካኬክኮኰኲኳኴኵኸኹኺኻኼኽኾወዉዊዋዌውዎዐዑዒዓዔዕዖዘዙዚዛዜዝዞዟዠዡዢዣዤዥዦዧየዩዪያዬይዮደዱዲዳዴድዶዷጀጁጂጃጄጅጆጇገጉጊጋጌግጎጐጒጓጔጕጠጡጢጣጤጥጦጧጨጩጪጫጬጭጮጯጰጱጲጳጴጵጶጷጸጹጺጻጼጽጾጿፀፁፂፃፄፅፆፈፉፊፋፌፍፎፏፐፑፒፓፔፕፖፗፘፙፚ፩፪፫፬፭፮፯፰፱፲፳፴፵፶፷፸፹፺፻]------------------------------
200 <p>
201 [ሀሁሂሃሄህሆለሉሊላሌልሎሏሐሑሒሓሔሕሖመሙሚማሜምሞሟሠሡሢሣሤሥሦረሩሪራሬርሮሯሰሱሲሳሴስሶሷሸሹሺሻሼሽሾሿቀቁቂቃቄቅቆቈቊቋቌቍቐቑቒቓቔቕቖቘቚቛቜቝበቡቢባቤብቦቧቨቩቪቫቬቭቮቯተቱቲታቴትቶቷቸቹቺቻቼችቾቿኀኁኂኃኄኅኆኈኊኋኌኍነኑኒናኔንኖኗኘኙኚኛኜኝኞኟአኡኢኣኤእኦኧከኩኪካኬክኮኰኲኳኴኵኸኹኺኻኼኽኾወዉዊዋዌውዎዐዑዒዓዔዕዖዘዙዚዛዜዝዞዟዠዡዢዣዤዥዦዧየዩዪያዬይዮደዱዲዳዴድዶዷጀጁጂጃጄጅጆጇገጉጊጋጌግጎጐጒጓጔጕጠጡጢጣጤጥጦጧጨጩጪጫጬጭጮጯጰጱጲጳጴጵጶጷጸጹጺጻጼጽጾጿፀፁፂፃፄፅፆፈፉፊፋፌፍፎፏፐፑፒፓፔፕፖፗፘፙፚ፩፪፫፬፭፮፯፰፱፲፳፴፵፶፷፸፹፺፻]
202 </p>
203 ------------------------------
204 [ሀሁሂሃሄህሆለሉሊላሌልሎሏሐሑሒሓሔሕሖመሙሚማሜምሞሟሠሡሢሣሤሥሦረሩሪራሬርሮሯሰሱሲሳሴስሶሷሸሹሺሻሼሽሾሿቀቁቂቃቄቅቆቈቊቋቌቍቐቑቒቓቔቕቖቘቚቛቜቝበቡቢባቤብቦቧቨቩቪቫቬቭቮቯተቱቲታቴትቶቷቸቹቺቻቼችቾቿኀኁኂኃኄኅኆኈኊኋኌኍነኑኒናኔንኖኗኘኙኚኛኜኝኞኟአኡኢኣኤእኦኧከኩኪካኬክኮኰኲኳኴኵኸኹኺኻኼኽኾወዉዊዋዌውዎዐዑዒዓዔዕዖዘዙዚዛዜዝዞዟዠዡዢዣዤዥዦዧየዩዪያዬይዮደዱዲዳዴድዶዷጀጁጂጃጄጅጆጇገጉጊጋጌግጎጐጒጓጔጕጠጡጢጣጤጥጦጧጨጩጪጫጬጭጮጯጰጱጲጳጴጵጶጷጸጹጺጻጼጽጾጿፀፁፂፃፄፅፆፈፉፊፋፌፍፎፏፐፑፒፓፔፕፖፗፘፙፚ፩፪፫፬፭፮፯፰፱፲፳፴፵፶፷፸፹፺፻]
205 ============================== MoinMoin style forced links
206 This is a ["Wiki"] page link.
207 This is a ["Wiki" wiki page] link with label.
208 This is a ["Wiki?param=1#fragment"] page link with query and fragment.
209 ------------------------------
210 <p>
211 This is a <a class="missing wiki" href="/wiki/Wiki" rel="nofollow">Wiki?</a> page link.
212 This is a <a class="missing wiki" href="/wiki/Wiki" rel="nofollow">wiki page?</a> link with label.
213 This is a <a class="missing wiki" href="/wiki/Wiki?param=1#fragment" rel="nofollow">Wiki?</a> page link with query and fragment.
214 </p>
215 ------------------------------
216 ============================== Wiki links with @version
217 wiki:page@12
218 WikiStart@12
219 WikiStart@12#heading
220 [WikiStart@12]
221 [WikiStart@12#heading]
222 This is a ["Wiki@12"] page link.
223 [wiki:WikiStart@12?format=txt v12 as text]
224 ------------------------------
225 <p>
226 <a class="missing wiki" href="/wiki/page?version=12" rel="nofollow">wiki:page@12?</a>
227 <a class="wiki" href="/wiki/WikiStart?version=12">WikiStart@12</a>
228 <a class="wiki" href="/wiki/WikiStart?version=12#heading">WikiStart@12#heading</a>
229 [<a class="wiki" href="/wiki/WikiStart?version=12">WikiStart@12</a>]
230 [<a class="wiki" href="/wiki/WikiStart?version=12#heading">WikiStart@12#heading</a>]
231 This is a <a class="missing wiki" href="/wiki/Wiki?version=12" rel="nofollow">Wiki@12?</a> page link.
232 <a class="wiki" href="/wiki/WikiStart?version=12&format=txt">v12 as text</a>
233 </p>
234 ------------------------------
235 ============================== WikiPageName with label
236 See details of the [WikiPageNames wiki page name] syntax.
237 Here's a [BadExample\fbad] example with special whitespace.
238 We can also [WikiLabels '"use [quotes]"']
239 or [WikiLabels "'use [quotes]'"]
240 ------------------------------
241 <p>
242 See details of the <a class="missing wiki" href="/wiki/WikiPageNames" rel="nofollow">wiki page name?</a> syntax.
243 Here's a <a class="missing wiki" href="/wiki/BadExample" rel="nofollow">bad?</a> example with special whitespace.
244 We can also <a class="missing wiki" href="/wiki/WikiLabels" rel="nofollow">"use [quotes]"?</a>
245 or <a class="missing wiki" href="/wiki/WikiLabels" rel="nofollow">'use [quotes]'?</a>
246 </p>
247 ------------------------------
248 ============================== WikiPageName with label should be strict...
249 new_channel_name [, '''integer''' handle [, '''boolean''' test]]
250 ------------------------------
251 <p>
252 new_channel_name [, <strong>integer</strong> handle [, <strong>boolean</strong> test]]
253 </p>
254 ------------------------------
255 ============================== InterTrac for wiki
256 t:wiki:InterTrac
257 trac:wiki:InterTrac
258 TRAC:wiki:InterTrac
259 [t:wiki:InterTrac intertrac]
260 [trac:wiki:InterTrac intertrac]
261 [trac:wiki:JonasBorgström jonas]
262 [TRAC:wiki:JonasBorgström jonas]
263 ------------------------------
264 <p>
265 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AInterTrac" title="wiki:InterTrac in The Trac Project"><span class="icon"></span>t:wiki:InterTrac</a>
266 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AInterTrac" title="wiki:InterTrac in The Trac Project"><span class="icon"></span>trac:wiki:InterTrac</a>
267 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AInterTrac" title="wiki:InterTrac in The Trac Project"><span class="icon"></span>TRAC:wiki:InterTrac</a>
268 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AInterTrac" title="wiki:InterTrac in The Trac Project"><span class="icon"></span>intertrac</a>
269 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AInterTrac" title="wiki:InterTrac in The Trac Project"><span class="icon"></span>intertrac</a>
270 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AJonasBorgstr%C3%B6m" title="wiki:JonasBorgström in The Trac Project"><span class="icon"></span>jonas</a>
271 <a class="ext-link" href="https://trac.edgewall.org/intertrac/wiki%3AJonasBorgstr%C3%B6m" title="wiki:JonasBorgström in The Trac Project"><span class="icon"></span>jonas</a>
272 </p>
273 ------------------------------
274 ============================== Wiki InterTrac shorthands
275 t:InterTrac
276 trac:InterTrac
277 TRAC:InterTrac
278 [t:InterTrac intertrac]
279 [trac:InterTrac intertrac]
280 [trac:JonasBorgström jonas]
281 ------------------------------
282 <p>
283 <a class="ext-link" href="https://trac.edgewall.org/intertrac/InterTrac" title="InterTrac in The Trac Project"><span class="icon"></span>t:InterTrac</a>
284 <a class="ext-link" href="https://trac.edgewall.org/intertrac/InterTrac" title="InterTrac in The Trac Project"><span class="icon"></span>trac:InterTrac</a>
285 <a class="ext-link" href="https://trac.edgewall.org/intertrac/InterTrac" title="InterTrac in The Trac Project"><span class="icon"></span>TRAC:InterTrac</a>
286 <a class="ext-link" href="https://trac.edgewall.org/intertrac/InterTrac" title="InterTrac in The Trac Project"><span class="icon"></span>intertrac</a>
287 <a class="ext-link" href="https://trac.edgewall.org/intertrac/InterTrac" title="InterTrac in The Trac Project"><span class="icon"></span>intertrac</a>
288 <a class="ext-link" href="https://trac.edgewall.org/intertrac/JonasBorgstr%C3%B6m" title="JonasBorgström in The Trac Project"><span class="icon"></span>jonas</a>
289 </p>
290 ------------------------------
291 ============================== InterWiki links
292 This is the original MeatBall:InterMapTxt wiki page.
293 Checkout the [tsvn:http://svn.edgewall.com/repos/trac Trac Repository].
294
295 complex link complex:a:test with positional arguments
296 complex link complex:a (not enough arguments)
297 complex link complex:a:test:more (too many arguments)
298
299 in trac.ini inter:b:resource
300 in trac.ini over:c:something overrides wiki
301
302 NoLink:ignored
303 NoLink:
304 NoLink: ...
305 ------------------------------
306 <p>
307 This is the original <a class="ext-link" href="http://www.usemod.com/cgi-bin/mb.pl?InterMapTxt" title="InterMapTxt in MeatBall..."><span class="icon"></span>MeatBall:InterMapTxt</a> wiki page.
308 Checkout the <a class="ext-link" href="tsvn:http://svn.edgewall.com/repos/trac" title="http://svn.edgewall.com/repos/trac in tsvn"><span class="icon"></span>Trac Repository</a>.
309 </p>
310 <p>
311 complex link <a class="ext-link" href="http://server/a/page/test?format=txt" title="resource test in a"><span class="icon"></span>complex:a:test</a> with positional arguments
312 complex link <a class="ext-link" href="http://server/a/page/?format=txt" title="resource in a"><span class="icon"></span>complex:a</a> (not enough arguments)
313 complex link <a class="ext-link" href="http://server/a/page/test:more?format=txt" title="resource test:more in a"><span class="icon"></span>complex:a:test:more</a> (too many arguments)
314 </p>
315 <p>
316 in trac.ini <a class="ext-link" href="http://inter/b/page/resource" title="Resource resource in b"><span class="icon"></span>inter:b:resource</a>
317 in trac.ini <a class="ext-link" href="http://over/c/page/something" title="c:something in over"><span class="icon"></span>over:c:something</a> overrides wiki
318 </p>
319 <p>
320 NoLink:ignored
321 <a class="missing wiki" href="/wiki/NoLink" rel="nofollow">NoLink?</a>:
322 <a class="missing wiki" href="/wiki/NoLink" rel="nofollow">NoLink?</a>: ...
323 </p>
324 ------------------------------
325 ============================== InterWiki links with parameters and fragment
326 See also MeatBall:InterMapTxt#there wiki page
327 and MeatBall:InterMapTxt?format=txt#there wiki page.
328
329 complex link complex:a:test?go#there with positional arguments
330 ------------------------------
331 <p>
332 See also <a class="ext-link" href="http://www.usemod.com/cgi-bin/mb.pl?InterMapTxt#there" title="InterMapTxt in MeatBall..."><span class="icon"></span>MeatBall:InterMapTxt#there</a> wiki page
333 and <a class="ext-link" href="http://www.usemod.com/cgi-bin/mb.pl?InterMapTxt&format=txt#there" title="InterMapTxt in MeatBall..."><span class="icon"></span>MeatBall:InterMapTxt?format=txt#there</a> wiki page.
334 </p>
335 <p>
336 complex link <a class="ext-link" href="http://server/a/page/test?format=txt&go#there" title="resource test in a"><span class="icon"></span>complex:a:test?go#there</a> with positional arguments
337 </p>
338 ------------------------------
339 ============================== Regression for #9712
340 This is not a link: x,://localhost
341 ------------------------------
342 <p>
343 This is not a link: x,:<em>localhost
344 </em></p>
345 ------------------------------
346 ============================== Wiki links with @version using unicode digits
347 WikiStart@₄₂
348 WikiStart@₄₂#heading
349 [WikiStart@₄₂]
350 [WikiStart@₄₂#heading]
351 ------------------------------
352 <p>
353 <a class="wiki" href="/wiki/WikiStart">WikiStart</a>@₄₂
354 <a class="wiki" href="/wiki/WikiStart">WikiStart</a>@₄₂#heading
355 [<a class="wiki" href="/wiki/WikiStart">WikiStart</a>@₄₂]
356 [<a class="wiki" href="/wiki/WikiStart">WikiStart</a>@₄₂#heading]
357 </p>
358 ------------------------------
359 """
360
361
362 RELATIVE_LINKS_TESTS = u"""
363 ============================== Relative to the project url
364 [//docs Documentation]
365 [//docs?param=1#fragment Documentation]
366 [//docs]
367 [//docs //docs]
368 [//docs?param=1#fragment]
369 [// Home]
370 [//]
371 [//?param=1#fragment]
372 ------------------------------
373 <p>
374 <a href="/docs">Documentation</a>
375 <a href="/docs?param=1#fragment">Documentation</a>
376 <a href="/docs">docs</a>
377 <a href="/docs">//docs</a>
378 <a href="/docs?param=1#fragment">docs</a>
379 <a href="/">Home</a>
380 <a href="/">//</a>
381 <a href="/?param=1#fragment">//</a>
382 </p>
383 ------------------------------
384 ============================== Relative to the base url
385 [/newticket?priority=high#fragment bug]
386 [/newticket?priority=high#fragment]
387 [/newticket]
388 [/newticket /newticket]
389 [/ Project]
390 [/]
391 [/?param=1#fragment]
392 ------------------------------
393 <p>
394 <a href="/newticket?priority=high#fragment">bug</a>
395 <a href="/newticket?priority=high#fragment">newticket</a>
396 <a href="/newticket">newticket</a>
397 <a href="/newticket">/newticket</a>
398 <a href="/">Project</a>
399 <a href="/">/</a>
400 <a href="/?param=1#fragment">/</a>
401 </p>
402 ------------------------------
403 ============================== Relative to the current page
404 [.]
405 [./]
406 [..]
407 [../]
408 [./../.]
409 [. this page]
410 [./Detail see detail]
411 [./Detail]
412 [./Detail ./Detail]
413 [.. see parent]
414 [../Other see other]
415 [../Other]
416 [../Other ../Other]
417 [.././../Other]
418 ------------------------------
419 <p>
420 <a class="wiki" href="/wiki/Main/Sub">.</a>
421 <a class="wiki" href="/wiki/Main/Sub">./</a>
422 <a class="missing wiki" href="/wiki/Main" rel="nofollow">..?</a>
423 <a class="missing wiki" href="/wiki/Main" rel="nofollow">../?</a>
424 <a class="missing wiki" href="/wiki/Main" rel="nofollow">./../.?</a>
425 <a class="wiki" href="/wiki/Main/Sub">this page</a>
426 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">see detail?</a>
427 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">Detail?</a>
428 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">./Detail?</a>
429 <a class="missing wiki" href="/wiki/Main" rel="nofollow">see parent?</a>
430 <a class="missing wiki" href="/wiki/Main/Other" rel="nofollow">see other?</a>
431 <a class="missing wiki" href="/wiki/Main/Other" rel="nofollow">Other?</a>
432 <a class="missing wiki" href="/wiki/Main/Other" rel="nofollow">../Other?</a>
433 <a class="missing wiki" href="/wiki/Other" rel="nofollow">Other?</a>
434 </p>
435 ------------------------------
436 ============================== Relative to the current page, in wiki realm
437 [wiki:. this page]
438 [wiki:./Detail]
439 [wiki:"./Detail"]
440 [wiki:./Detail ./Detail]
441 [wiki:./Detail see detail]
442 [wiki:.. see parent]
443 [wiki:../Other see other]
444 [wiki:.././../Other]
445 ["."]
446 [".?param=1#fragment"]
447 ["./Detail"]
448 ["./Detail?param=1#fragment"]
449 [".."]
450 ["..?param=1#fragment"]
451 ["../Other"]
452 ["../Other?param=1#fragment"]
453 [".././../Other"]
454 ------------------------------
455 <p>
456 <a class="wiki" href="/wiki/Main/Sub">this page</a>
457 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">Detail?</a>
458 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">Detail?</a>
459 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">./Detail?</a>
460 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">see detail?</a>
461 <a class="missing wiki" href="/wiki/Main" rel="nofollow">see parent?</a>
462 <a class="missing wiki" href="/wiki/Main/Other" rel="nofollow">see other?</a>
463 <a class="missing wiki" href="/wiki/Other" rel="nofollow">Other?</a>
464 <a class="wiki" href="/wiki/Main/Sub">.</a>
465 <a class="wiki" href="/wiki/Main/Sub?param=1#fragment">.</a>
466 <a class="missing wiki" href="/wiki/Main/Sub/Detail" rel="nofollow">Detail?</a>
467 <a class="missing wiki" href="/wiki/Main/Sub/Detail?param=1#fragment" rel="nofollow">Detail?</a>
468 <a class="missing wiki" href="/wiki/Main" rel="nofollow">..?</a>
469 <a class="missing wiki" href="/wiki/Main?param=1#fragment" rel="nofollow">..?</a>
470 <a class="missing wiki" href="/wiki/Main/Other" rel="nofollow">Other?</a>
471 <a class="missing wiki" href="/wiki/Main/Other?param=1#fragment" rel="nofollow">Other?</a>
472 <a class="missing wiki" href="/wiki/Other" rel="nofollow">Other?</a>
473 </p>
474 ------------------------------
475 ============================== Relative to the current page, as CamelCase
476 OnePage/SubPage
477 ./SubPage
478 ../SiblingPage
479 .././../HigherPage
480 /TopPage
481 ------------------------------
482 <p>
483 <a class="missing wiki" href="/wiki/Main/OnePage/SubPage" rel="nofollow">OnePage/SubPage?</a>
484 <a class="missing wiki" href="/wiki/Main/Sub/SubPage" rel="nofollow">./SubPage?</a>
485 <a class="missing wiki" href="/wiki/Main/SiblingPage" rel="nofollow">../SiblingPage?</a>
486 <a class="missing wiki" href="/wiki/HigherPage" rel="nofollow">.././../HigherPage?</a>
487 <a class="missing wiki" href="/wiki/TopPage" rel="nofollow">/TopPage?</a>
488 </p>
489 ------------------------------
490 ============================== Relative to the current page with query strings and fragments
491 [#topic see topic]
492 [?param=1#topic see topic]
493 [.#topic see topic]
494 [.?param=1#topic see topic]
495 [./#topic see topic]
496 [./?param=1#topic see topic]
497 [./Detail#topic see detail]
498 [./Detail?param=1#topic see detail]
499 [./Detail?param=1#topic]
500 [..#topic see parent]
501 [..?param=1#topic see parent]
502 [../#topic see parent]
503 [../?param=1#topic see parent]
504 [../Other#topic see other]
505 [../Other?param=1#topic see other]
506 [../Other?param=1#topic]
507 [../Other/#topic see other]
508 [../Other/?param=1#topic see other]
509 ------------------------------
510 <p>
511 <a class="wiki" href="/wiki/Main/Sub#topic">see topic</a>
512 <a class="wiki" href="/wiki/Main/Sub?param=1#topic">see topic</a>
513 <a class="wiki" href="/wiki/Main/Sub#topic">see topic</a>
514 <a class="wiki" href="/wiki/Main/Sub?param=1#topic">see topic</a>
515 <a class="wiki" href="/wiki/Main/Sub#topic">see topic</a>
516 <a class="wiki" href="/wiki/Main/Sub?param=1#topic">see topic</a>
517 <a class="missing wiki" href="/wiki/Main/Sub/Detail#topic" rel="nofollow">see detail?</a>
518 <a class="missing wiki" href="/wiki/Main/Sub/Detail?param=1#topic" rel="nofollow">see detail?</a>
519 <a class="missing wiki" href="/wiki/Main/Sub/Detail?param=1#topic" rel="nofollow">Detail?</a>
520 <a class="missing wiki" href="/wiki/Main#topic" rel="nofollow">see parent?</a>
521 <a class="missing wiki" href="/wiki/Main?param=1#topic" rel="nofollow">see parent?</a>
522 <a class="missing wiki" href="/wiki/Main#topic" rel="nofollow">see parent?</a>
523 <a class="missing wiki" href="/wiki/Main?param=1#topic" rel="nofollow">see parent?</a>
524 <a class="missing wiki" href="/wiki/Main/Other#topic" rel="nofollow">see other?</a>
525 <a class="missing wiki" href="/wiki/Main/Other?param=1#topic" rel="nofollow">see other?</a>
526 <a class="missing wiki" href="/wiki/Main/Other?param=1#topic" rel="nofollow">Other?</a>
527 <a class="missing wiki" href="/wiki/Main/Other#topic" rel="nofollow">see other?</a>
528 <a class="missing wiki" href="/wiki/Main/Other?param=1#topic" rel="nofollow">see other?</a>
529 </p>
530 ------------------------------
531 """
532
533
534 SPLIT_PAGE_NAMES_TESTS = u"""
535 ============================== Splitting relative links
536 [//WikiPage]
537 [/WikiPage]
538 [./WikiPage]
539 [../WikiPage]
540 [//WikiPage?param=1#fragment]
541 [/WikiPage?param=1#fragment]
542 [./WikiPage?param=1#fragment]
543 [../WikiPage?param=1#fragment]
544 But not [./wiki_page]
545 And not [../WikiPage WikiPage]
546 ------------------------------
547 <p>
548 <a href="/WikiPage">Wiki Page</a>
549 <a href="/WikiPage">Wiki Page</a>
550 <a class="missing wiki" href="/wiki/Main/Sub/WikiPage" rel="nofollow">Wiki Page?</a>
551 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
552 <a href="/WikiPage?param=1#fragment">Wiki Page</a>
553 <a href="/WikiPage?param=1#fragment">Wiki Page</a>
554 <a class="missing wiki" href="/wiki/Main/Sub/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
555 <a class="missing wiki" href="/wiki/Main/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
556 But not <a class="missing wiki" href="/wiki/Main/Sub/wiki_page" rel="nofollow">wiki_page?</a>
557 And not <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">WikiPage?</a>
558 </p>
559 ------------------------------
560 ============================== Splitting scoped links
561 [wiki:WikiPage]
562 [wiki:./WikiPage]
563 [wiki:../WikiPage]
564 [wiki:./.././WikiPage]
565 [wiki:"./.././WikiPage"]
566 [wiki:WikiPage?param=1#fragment]
567 [wiki:./WikiPage?param=1#fragment]
568 [wiki:../WikiPage?param=1#fragment]
569 But not [wiki:./wiki_page]
570 And not [wiki:../WikiPage WikiPage]
571 ------------------------------
572 <p>
573 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
574 <a class="missing wiki" href="/wiki/Main/Sub/WikiPage" rel="nofollow">Wiki Page?</a>
575 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
576 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
577 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
578 <a class="missing wiki" href="/wiki/Main/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
579 <a class="missing wiki" href="/wiki/Main/Sub/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
580 <a class="missing wiki" href="/wiki/Main/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
581 But not <a class="missing wiki" href="/wiki/Main/Sub/wiki_page" rel="nofollow">wiki_page?</a>
582 And not <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">WikiPage?</a>
583 </p>
584 ------------------------------
585 ============================== Splitting internal free links
586 ["WikiPage"]
587 ["./WikiPage"]
588 ["../WikiPage"]
589 ["./.././WikiPage"]
590 ["WikiPage?param=1#fragment"]
591 ["./WikiPage?param=1#fragment"]
592 ["../WikiPage?param=1#fragment"]
593 But not ["./wiki_page"]
594 And not ["../WikiPage" WikiPage]
595 ------------------------------
596 <p>
597 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
598 <a class="missing wiki" href="/wiki/Main/Sub/WikiPage" rel="nofollow">Wiki Page?</a>
599 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
600 <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">Wiki Page?</a>
601 <a class="missing wiki" href="/wiki/Main/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
602 <a class="missing wiki" href="/wiki/Main/Sub/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
603 <a class="missing wiki" href="/wiki/Main/WikiPage?param=1#fragment" rel="nofollow">Wiki Page?</a>
604 But not <a class="missing wiki" href="/wiki/Main/Sub/wiki_page" rel="nofollow">wiki_page?</a>
605 And not <a class="missing wiki" href="/wiki/Main/WikiPage" rel="nofollow">WikiPage?</a>
606 </p>
607 ------------------------------
608 """
609
610
611 SCOPED_LINKS_TESTS = u"""
612 ============================== Scoped links for hierarchical pages
613 ThirdLevel
614 [wiki:ThirdLevel]
615 OtherThirdLevel
616 [wiki:OtherThirdLevel]
617 SecondLevel/OtherThirdLevel
618 [wiki:SecondLevel/OtherThirdLevel]
619 SecondLevel
620 [wiki:SecondLevel]
621 FirstLevel
622 [wiki:FirstLevel]
623 TestPage
624 [wiki:TestPage]
625 MissingPage
626 [wiki:MissingPage]
627 FirstLevel/MissingPage
628 [wiki:FirstLevel/MissingPage]
629 SecondLevel/MissingPage
630 [wiki:SecondLevel/MissingPage]
631 MissingFirstLevel/MissingPage
632 [wiki:MissingFirstLevel/MissingPage]
633 ["/OtherThirdLevel"]
634 [wiki:/OtherThirdLevel]
635 [wiki:/OtherThirdLevel /OtherThirdLevel]
636 ------------------------------
637 <p>
638 <a class="wiki" href="/wiki/FirstLevel/SecondLevel/ThirdLevel">ThirdLevel</a>
639 <a class="wiki" href="/wiki/FirstLevel/SecondLevel/ThirdLevel">ThirdLevel</a>
640 <a class="wiki" href="/wiki/FirstLevel/SecondLevel/OtherThirdLevel">OtherThirdLevel</a>
641 <a class="wiki" href="/wiki/FirstLevel/SecondLevel/OtherThirdLevel">OtherThirdLevel</a>
642 <a class="wiki" href="/wiki/FirstLevel/SecondLevel/OtherThirdLevel">SecondLevel/OtherThirdLevel</a>
643 <a class="wiki" href="/wiki/FirstLevel/SecondLevel/OtherThirdLevel">SecondLevel/OtherThirdLevel</a>
644 <a class="wiki" href="/wiki/FirstLevel/SecondLevel">SecondLevel</a>
645 <a class="wiki" href="/wiki/FirstLevel/SecondLevel">SecondLevel</a>
646 <a class="wiki" href="/wiki/FirstLevel">FirstLevel</a>
647 <a class="wiki" href="/wiki/FirstLevel">FirstLevel</a>
648 <a class="wiki" href="/wiki/TestPage">TestPage</a>
649 <a class="wiki" href="/wiki/TestPage">TestPage</a>
650 <a class="missing wiki" href="/wiki/FirstLevel/SecondLevel/MissingPage" rel="nofollow">MissingPage?</a>
651 <a class="missing wiki" href="/wiki/FirstLevel/SecondLevel/MissingPage" rel="nofollow">MissingPage?</a>
652 <a class="missing wiki" href="/wiki/FirstLevel/MissingPage" rel="nofollow">FirstLevel/MissingPage?</a>
653 <a class="missing wiki" href="/wiki/FirstLevel/MissingPage" rel="nofollow">FirstLevel/MissingPage?</a>
654 <a class="missing wiki" href="/wiki/FirstLevel/SecondLevel/MissingPage" rel="nofollow">SecondLevel/MissingPage?</a>
655 <a class="missing wiki" href="/wiki/FirstLevel/SecondLevel/MissingPage" rel="nofollow">SecondLevel/MissingPage?</a>
656 <a class="missing wiki" href="/wiki/FirstLevel/SecondLevel/MissingFirstLevel/MissingPage" rel="nofollow">MissingFirstLevel/MissingPage?</a>
657 <a class="missing wiki" href="/wiki/FirstLevel/SecondLevel/MissingFirstLevel/MissingPage" rel="nofollow">MissingFirstLevel/MissingPage?</a>
658 <a class="missing wiki" href="/wiki/OtherThirdLevel" rel="nofollow">OtherThirdLevel?</a>
659 <a class="missing wiki" href="/wiki/OtherThirdLevel" rel="nofollow">OtherThirdLevel?</a>
660 <a class="missing wiki" href="/wiki/OtherThirdLevel" rel="nofollow">/OtherThirdLevel?</a>
661 </p>
662 ------------------------------
663 """
664
665
666 SAFE_INTERWIKI_TESTS = u"""
667 ============================== InterWiki with safe_schemes
668 This is the original MeatBall:InterMapTxt wiki page.
669
670 Checkout the [tsvn:http://svn.edgewall.com/repos/trac Trac Repository].
671
672 complex link complex:a:test with positional arguments.
673
674 js:"alert(1)" javasc:"ript:alert(1)"
675 ------------------------------
676 <p>
677 This is the original <a class="ext-link" href="http://www.usemod.com/cgi-bin/mb.pl?InterMapTxt" title="InterMapTxt in MeatBall..."><span class="icon"></span>MeatBall:InterMapTxt</a> wiki page.
678 </p>
679 <p>
680 Checkout the <a class="ext-link" href="tsvn:http://svn.edgewall.com/repos/trac" title="http://svn.edgewall.com/repos/trac in tsvn"><span class="icon"></span>Trac Repository</a>.
681 </p>
682 <p>
683 complex link <a class="ext-link" href="http://server/a/page/test?format=txt" title="resource test in a"><span class="icon"></span>complex:a:test</a> with positional arguments.
684 </p>
685 <p>
686 js:"alert(1)" javasc:"ript:alert(1)"
687 </p>
688 ------------------------------
689 """
690
691
693 tc.env.config.set('wiki', 'render_unsafe_content', True)
694 now = datetime_now(utc)
695 wiki0 = WikiPage(tc.env)
696 wiki0.name = 'Main/Sub'
697 wiki0.text = '--'
698 wiki0.save('joe', 'subpage', '::1', now)
699
700 wiki1 = WikiPage(tc.env)
701 wiki1.name = 'TestPage'
702 wiki1.text = '--'
703 wiki1.save('joe', 'normal WikiPageNames', '::1', now)
704
705 wiki2 = WikiPage(tc.env)
706 wiki2.name = 'Space 1 23'
707 wiki2.text = '--'
708 wiki2.save('joe', 'not a WikiPageNames', '::1', now)
709
710 wiki3 = WikiPage(tc.env)
711 wiki3.name = u"C'est l'\xe9t\xe9"
712 wiki3.text = '--'
713 wiki3.save('joe', 'unicode WikiPageNames', '::1', now)
714
715 imt = WikiPage(tc.env)
716 imt.name = u"InterMapTxt"
717 imt.text = """
718 This is the InterMapTxt
719 ----
720 {{{
721 MeatBall http://www.usemod.com/cgi-bin/mb.pl? # $1 in MeatBall...
722 tsvn tsvn:
723 complex http://server/$1/page/$2?format=txt # resource $2 in $1
724 over http://unused/? # Overridden in trac.ini
725 js javascript:
726 javasc javasc
727 }}}
728 ----
729 {{{
730 nolink http://noweb
731 }}}
732 """
733 imt.save('joe', 'test InterWiki links', '::1', now)
734 tc.env.config.set('interwiki', 'inter',
735 'http://inter/$1/page/$2 Resource $2 in $1')
736 tc.env.config.set('interwiki', 'over',
737 'http://over/$1/page/$2')
738
739 w = WikiPage(tc.env)
740 w.name = 'FirstLevel'
741 w.text = '--'
742 w.save('joe', 'first level of hierarchy', '::1', now)
743
744 w = WikiPage(tc.env)
745 w.name = 'FirstLevel/SecondLevel'
746 w.text = '--'
747 w.save('joe', 'second level of hierarchy', '::1', now)
748
749 w = WikiPage(tc.env)
750 w.name = 'FirstLevel/SecondLevel/ThirdLevel'
751 w.text = '--'
752 w.save('joe', 'third level of hierarchy', '::1', now)
753
754 w = WikiPage(tc.env)
755 w.name = 'FirstLevel/SecondLevel/OtherThirdLevel'
756 w.text = '--'
757 w.save('joe', 'other third level of hierarchy', '::1', now)
758
759 tc.env.db_transaction("INSERT INTO ticket (id) VALUES ('123')")
760
761
764
765
769
770
772 wiki_setup(tc)
773 tc.env.config.set('wiki', 'render_unsafe_content', 'false')
774 tc.env.config.set('wiki', 'safe_schemes',
775 'file,ftp,git,irc,http,https,ssh,svn,tsvn')
776
777
779 suite = unittest.TestSuite()
780 suite.addTest(formatter.suite(TEST_CASES, wiki_setup, __file__,
781 wiki_teardown))
782 suite.addTest(formatter.suite(RELATIVE_LINKS_TESTS, wiki_setup, __file__,
783 wiki_teardown,
784 context=('wiki', 'Main/Sub')))
785 suite.addTest(formatter.suite(SPLIT_PAGE_NAMES_TESTS, wiki_setup_split,
786 __file__, wiki_teardown,
787 context=('wiki', 'Main/Sub')))
788 suite.addTest(formatter.suite(SCOPED_LINKS_TESTS, wiki_setup, __file__,
789 wiki_teardown,
790 context=('wiki',
791 'FirstLevel/SecondLevel/ThirdLevel')))
792 suite.addTest(formatter.suite(SAFE_INTERWIKI_TESTS,
793 wiki_setup_safe_interwiki, __file__,
794 wiki_teardown))
795 return suite
796
797 if __name__ == '__main__':
798 unittest.main(defaultTest='suite')
799