Admin Forum:Weird effect with the if parser function

I've been working with parser functions for years now and I've never seen anything like this before. It's gotta be some kinda bug, but I wanted to run it past people smarter than me before I reported. I have a simple link template called tardis:template:Delgado. It's basic function is to link to a particular part of the article tardis:the Master having to do with the interpretation by an actor named tardis:Roger Delgado. So basically, you type Delgado and it creates a link displaying as "the Master" but pointing towards a particular section of an article. Fine. Straightforward enough.

But, I wanted to be able to account for the fact that sometimes you need to be able to create a link for The Master, so that you can start a sentence with a capital The.

So here's the simple #if of it all:

Seems like it'd work, right? And it does — for the first option. If you type, you get a proper section link. But if you just type you just get a link to the Master.

I couldn't understand it, so I dug deeper and then found that if there was no space in the second display statement, the link was fine. Which means that the following two things work:

So my question is why? Why is the space okay in the first condition, but not in the second? I've never seen an #if statement be so finicky with spaces like this. Is this a MW 1.19 bug? 23:01: Fri 16 Nov 2012


 * I can't reproduce this bug, tardis:User:Acer4666/sandbox, the links seem to point to the right section-- Category:Acer4666 00:07, November 17, 2012 (UTC)


 * I couldn't reproduce this bug on tardis either, but it looks like that's because CzechOut has already fixed the template (and forgot to mention that detail). I did try to recreate the bug on my test wiki at w:c:mathmagician:IfLinkTest, but I still can't see any problem.


 * On a related note, the following should also work for the template:

he Master
 * Yeah I knew it was fixed, I unfixed it in my sandbox page but it still works-- Category:Acer4666 00:20, November 17, 2012 (UTC)
 * I can see that it works on your page, Acer. Which is completely confusing to me. I've gone ahead and created the next in the series, and am still getting the error. Compare and contrast tardis:template:Delgado and tardis:template:Ainley please. (Again, we're focusing on why the lowercase t "the Master" link behaves differently at Delgado than it does at Ainley.) 00:45: Sat 17 Nov 2012
 * I can see that it works on your page, Acer. Which is completely confusing to me. I've gone ahead and created the next in the series, and am still getting the error. Compare and contrast tardis:template:Delgado and tardis:template:Ainley please. (Again, we're focusing on why the lowercase t "the Master" link behaves differently at Delgado than it does at Ainley.) 00:45: Sat 17 Nov 2012


 * I don't see the effect - but these templates are acting oddly when placed on the same page. It's like they're interfering with one another. On tardis:User:Acer4666/sandbox, notice how the second Delgado template is linking to the Ainley section. This may be the bug with section links described here-- Category:Acer4666 01:06, November 17, 2012 (UTC)


 * It's good that we've finally been able to reproduce that problem at least. -452 01:27, November 17, 2012 (UTC)


 * To show &amp;nbsp;, type &amp;amp;nbsp; (and thanks for the new example) -452 00:47, November 17, 2012 (UTC)


 * I may not be fully understanding the issue, but perhaps you've reproduced the section link bug mentioned here: User_blog:DaNASCAT/Technical_Update:_November_13,_2012 (Acer4666 beat me to it.)
 * I've created a test template here: Sandbox_452/1, in use here: Sandbox_452 (Feel free to experiment with those pages)
 * I'm getting section links for all cases, but in the last example, where I've used the parameter "blah", the last two links are the same, when they should be different, as the others are. -452 01:09, November 17, 2012 (UTC)


 * Well the 13 November bug linked above wasn't the problem I was describing, but it definitely makes the idea behind these templates unworkable. We've gotta be able to link to different sections of tardis:the Master to write many of our articles.


 * The thing I'm actually talking about is that the Delgado template —at least as it sits at tardis:template:Delgado links to a specific section, as shown in the first example under the "usage" section head. By contrast tardis:template:Ainley does not link to a specific section in that first, lowercase the example. The only difference between the two codes is that, at Delgado, I've essentially created one word by using a non-breaking space in the pipe switch: the&amp;nbsp;Master. At Ainley, I've just typed the Master. There's really no reason for this behaviour, as far as I can see. 01:17: Sat 17 Nov 2012


 * Thanks, I see what you mean about it not working in the usage section.
 * I've created tardis:user:452/sandbox9, tardis:user:452/sandbox8, tardis:user:452/sandbox7, tardis:user:452/sandbox6 - and I appear to be getting the expected results when calling the template only once on a page, I'll keep experimenting. -452 01:27, November 17, 2012 (UTC)
 * Specifically, tardis:user:452/sandbox6 is using, and getting the correct link. -452 01:32, November 17, 2012 (UTC)
 * What happens if you edit tardis:Template:Ainley/doc and change to  ? -452 01:32, November 17, 2012 (UTC)


 * It doesn't work at all. It renders literally —i.e. . The spaces allow the software to see the middle bit as a template with the name PAGENAME.  01:35: Sat 17 Nov 2012
 * Now I'm even more confused than ever. I've just used 452's tardis sandbox to write a natural-ish short paragraph using these two templates in various situations, and they link correctly, every time. I don't get it — but I guess I should be glad that they work correctly on a page outside of the template namespace, and that they don't seem plagued at all by the 13 November bug. 01:43: Sat 17 Nov 2012


 * Yeah, the problem only appears to be occurring on the template page itself. I've reproduced it on tardis:user:452/sandbox5, but I'm still trying to work out why it's happening... -452 01:48, November 17, 2012 (UTC)
 * Oh, I got it. It is just the section heading problem. The intro of tardis:Template:Ainley/doc links to "the Master", so the first link in usage is actually the second link to the same page, remove that link from the intro to test. Hopefully they'll fix the bug next week. -452 02:07, November 17, 2012 (UTC)
 * Just beat me to it! But that doesn't explain why this only occurs when the piped part of the link contains a space?-- Category:Acer4666 02:13, November 17, 2012 (UTC)
 * Ohhh I seeee, it's not the presence of a space, it's the fact the two link texts are different. Nice one 452!-- Category:Acer4666 02:17, November 17, 2012 (UTC)

There's still a chance of you running into this in an article if you try to use both of those templates on the same page - even if you add a nbsp, because any time the base page and link text are the same, the second link will be messed up. (I'm all done with my tardis sandbox pages, feel free to delete them) -452 02:30, November 17, 2012 (UTC)


 * Hmmmm, so the bug is that if you make a link to the article alone, you can't then make a link to a section? No, that's not right, because the second link under "usage" was working. And the first link works so long as there is no space in the piped text. I'm so confused about what the 13 November bug actually is. 02:42: Sat 17 Nov 2012
 * Wait, wait, wait. The error appears when the base page (the Master) is the same as the piped text (the Master) —is that right? So if that's true, then is the solution simply to make the base page the Master and the piped text The Master? Does capitalisation count here? 02:48: Sat 17 Nov 2012
 * Yeah, we didn't understand it until just now either, but that's basically it. The bug happens when the both base page, and the link text (AKA piped text) are the same, so that's why adding nbsp made the bug go away on that page, because it made the link texts different, and that's why the bug didn't effect the second example, because the capitalisation was different. -452 02:59, November 17, 2012 (UTC)
 * Oh, I see what you mean - I just tested the captitalisation of the first letter of the base page - no it doesn't work. I think the reason for that is because the wiki parser makes the first letter uppercase automatically.  Hover over a link to the Master and look in the status bar and you'll see it links to The Master -452 03:04, November 17, 2012 (UTC)