Template:URL/testcases
| Code | Result | Sandbox Result |
|---|---|---|
| {{URL}} | {{URL|example.com|optional display text}} |
{{URL|example.com|optional display text}} |
| {{URL| http:// }} | [http:// ] | [http:// ] |
| {{URL| example.com }} | example |
example |
| {{URL| EXAMPLE.COM }} | example |
example |
| {{URL| www.example.com }} | www |
www |
| {{URL| WWW.EXAMPLE.COM }} | www |
www |
| {{URL| http://www.example.com }} | www |
www |
| {{URL| https://www.example.com }} | www |
www |
| {{URL| http://www.example.com/ }} | www |
www |
| {{URL| https://www.EXAMPLE.cOm }} | www |
www |
| {{URL| HTTPS://www.EXAMPLE.cOm/ }} | www |
www |
| {{URL| https://www.example.com/ }} | www |
www |
| {{URL| http://example.com }} | example |
example |
| {{URL| https://example.com }} | example |
example |
| {{URL| ftp://example.com }} | example |
example |
| {{URL| ftp://www.example.com }} | www |
www |
| {{URL| http://www.example.com/foo/bar }} | www |
www |
| {{URL| http://www.example.com/foo/bar/ }} | www |
www |
| {{URL| http://www.example.com/foO/BaR }} | www |
www |
| {{URL| https://www.example.com/foo/bar }} | www |
www |
| {{URL| http://example.com/foo/bar }} | example |
example |
| {{URL| https://example.com/foo/bar }} | example |
example |
| {{URL| example.com/foo/bar }} | example |
example |
| {{URL| www.example.com/foo/bar }} | www |
www |
| {{URL| http://example.com/foo/bar | }} | example |
example |
| {{URL| http://example.com/foo/bar | link }} | link | link |
| {{URL| https://example.com/foo/bar | link }} | link | link |
| {{URL| example.com/foo/bar | link }} | link | link |
| {{URL| www.example.com/foo/bar | link }} | link | link |
| {{URL| www.example.com/foo/bar | 捦挺挎 }} | 捦挺挎 | 捦挺挎 |
| {{URL| www.example.com/foo/捦挺挎/bar | link }} | link | link |
| {{URL| عمان.icom.museum }} | عمان |
عمان |
| {{URL| http://عمان.icom.museum }} | عمان |
عمان |
| {{URL| 1964thetribute.com }} | 1964thetribute |
1964thetribute |
| {{URL| 1964thetribute.com | 1964thetribute.com }} | 1964thetribute.com | 1964thetribute.com |
| {{URL| http://www.example.com/foo/bar?a=b&c=d }} | {{URL|example.com|optional display text}} |
{{URL|example.com|optional display text}} |
| {{URL|1= http://www.example.com/foo/bar?a=b&c=d }} | www |
www |
Warning examples
[edit]If the URL may contain equal signs, the parameters MUST be numbered explicitly to have the template work as expected (otherwise, parameter value ovvrides will occur) ; this especially occurs when an explicit display text is provided in parameter 2, something that was forgotten when they were incorrectly listed as "Pathological examples" in the next section).
There's absolutely never any problem when the parameter 2 is explicitly passed, but in this case, using this template is not even needed, and standard Wiki link syntax will be fully equivalent and in fact simpler to edit and faster to compute on the server.
| Code | Result | Sandbox Result |
|---|---|---|
| {{URL| 1=http://www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=umhistmath;cc=umhistmath;rgn=full%20text;idno=ABS3153.0001.001;didno=ABS3153.0001.001;view=image;seq=00000140| 2=link}} | link | link |
| {{URL| 1=www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=umhistmath;cc=umhistmath;rgn=full%20text;idno=ABS3153.0001.001;didno=ABS3153.0001.001;view=image;seq=00000140| 2=link}} | link | link |
Note that the second example does not work to generate a working link because the "http://" prefix fails to be implied on too long URLs. The first example specifies the full URL and correctly generates a link with this exact URL, and with the specified display text.
Pathological examples
[edit]All these cases above do not work as expected (and would cause severe performance problems if trying to transform the displayed URL), because of a limitation of {{#titleparts:}} which limits its parameter to a maximum length of 255 characters, and then stops working and returns its full parameter when its specified string is longer, or when the URL contains a query string that includes sequences normally not allowed in MediaWiki page names (such as characters represented in the "%xx" URL-encoding). The templates first tests that the leading URI scheme (or the leading domain name) can be extracted from the specified URL, using code like in the following test cases : if this fails, it won't attempt to generate a full URL (by prepending a default URI scheme "http://") or to shorten the display text :
- {{#titleparts:http://www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=um|1|1}}
- returns: Http: (this works)
- {{#titleparts:http://www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=umhistmath;cc=umhistmath;rgn=full+text;idno=ABS3153.0001.001;didno=ABS3153.0001.001;view=image;seq=00000140;some-too-long-query-string-so-that-the-whole-url-is-longer-than-255-characters;some-too-long-query-string-so-that-the-whole-url-is-longer-than-255-characters;some-too-long-query-string-so-that-the-whole-url-is-longer-than-255-characters;some-too-long-query-string-so-that-the-whole-url-is-longer-than-255-characters|1|1}}
- {{#titleparts:http://www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=umhistmath;cc=umhistmath;rgn=full%20text;idno=ABS3153.0001.001;didno=ABS3153.0001.001;view=image;seq=00000140|1|1}}
- {{#titleparts:http://www.example.com/?1=%2Ex|1|1}}
- returns: http://www.example.com/?1=%2Ex
- {{#titleparts:http://www.example.com/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z?1=x|1|1}}
- returns: Http: (this works, no limitation in the total number of slashes)
In order to detect if {{#titleparts:}} really returns the expected first segment sliced by slashes, it checks that the returned string is different from its parameter. However, when the source string contains no slash at all, the source string will be returned, with its first letter capitalized. To make sure that it does not incorrectly detect that {{#titleparts:}} rejected the input string and returned it unchanged, this template first converts the URL to lowercase : the first slice returned (when the string is accepted) will be converted with a leading capital.
Warning: This test works indifferently if this first slice is an URI scheme (because it won't be alone and so this slice will always be different from the full URL), or if the specified URL just consists in a single valid domain name filling the first slice (without any URI scheme or resource path, such as "NASCAR.com", which is first converted to "nascar.com", before being tested with titleparts: that will change it into "Nascar.com"). This test is dependant on the fact that Wikipedia page titles always have their first letter converted to capital by {{#titleparts:}}, but this test would not work on Wiktionnary where lettercase is significant on all letters, and not altered by {{#titleparts:}}.