betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

24 March 2007

A Story of Workarounds and Bugfixes

Footnote here

I like bugfixing. No idea if it's my nickname that's at fault (the nickname was there before my appetite for bugfixing), but I also seem to have some success with it. Sometimes it can get a nice twist. Take for example this problem Zwiki had in rendering footnotes in RST pages: It looked like we would need a workaround in the code to make the problem go away, a special case with extra checks, bells and whistles. I took the plunge into the code and started looking for where to apply that...

(This part always reminds me of Diomedes Spinellis Book "Code Reading".) Using "tags" in vi is the first weapon of the bug hunter, sprinkling the code with "print" statements the second. Pretty quickly I found the spot to apply the "special case" to be somewhere within a function called markLinksIn. There I started to build my special case. This function identifies wiki links inside the page text, it already has special treatment e.g. for wiki links that are inside other links. As I was trying to understand the logical flow of the code, I looked through the method within_literal, which does part of those checks, something similar to what I was building.

My "special check" was trying to detect RestructuredText footnote or citation markup around a zwiki freeform link, for example [1]_ would be the marker for footnote 1, while .. [1] would start the actual footnote display. The general code gave me the "coordinates" of the found link (the position of the '[' and ']' in the overall text). I tried to "look back" and "look forward" from those positions to detect the special RST markup. But it just didn't work, it wouldn't detect the footnote markup. "print" to the rescue, I started to print out what I had "seen looking back" and surprise! surprise! at this point in the code the RST footnote had already been transformed to an html link element, so looking for .. couldn't possibly have found anything.

Now I hope I didn't lost you till here... because if there was a link around the wiki freeform link, then that should already have been detected by the existing code, specifically the within_literal method. But why wasn't it detected? Some more friendly and helpful "print" statements later (and while chatting with Simon on #zwiki) I spotted the problem: The find function was looking for <a href= while RST generates tags of the form <a name="..." href="..." (which is perfectly legal, just looks unusual). It took me a little bit more time to actually fix the bug, but at that time the poor critter was already lost.

Now the funny thing about this story is how everybody was shouting "we need a special case, oh my, it will clutter up our code, but we need it". (I'm not exempting myself from this, in fact I was halfway into actually writing that special case code.) But in the end it was just a small bug, stemming from the way we usually see HTML links in difference to what HTML links really can look like.

Posted by betabug at 10:57 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Frühlingsanfang | Main | Ημερομηνίες και άνθρωποι >>
There are no comments.
You can trackback to:
There are no trackbacks.