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