A short story on a tiny error

published at 13.04.2017 18:17 by Jens Weller
Save to Instapaper Pocket

Well, lets make this clear, this isn't an article about best practices. Its about the little errors that happen in everyday life, and how they can go on undetected for quite a while. It started with a hint on reddit from Vittorio Romeo on last weeks C++ Blogroll, that the links for the videos didn't work.

So, I did take a quick look for the code, but couldn't see the error. The blogroll is generated by my RSS Tool, which also generates other lists, like the monthly overview or the list of user groups. In common has the code, that at the time I wrote it, it was always a small feature, its just a little method loading the needed data from DB and processing it. Then with time a few other tiny features get added, like embedding the videos, listing the videos below...  The result is an HTML snippet, which is copied to the clipboard. At the base, I use QString and its arg functionality to create the HTML.

When I refactored the very short feature to embed the videos into the blogroll, I made the decision to use a C++11 raw string:

QString ythtml = (R"(... href=\"%1\" rel=\"nofollow\"...)");

And in the moment, a small oversight: the escaped quotes are no longer needed in a raw string. Its not even copy & paste, as the blogroll worked until this change. Also, being part of a feature, where the content is embedded into the website (this works! ;) ), it went unnoticed for one and a half years.

A future todo is to see, if all code generating lists, can be refactored into a set of code doing only this. Which would move this code from the application domain into the library domain. Also using an HTML parser like gumbo to test for errors is worth a thought.

 

 

Join the Meeting C++ patreon community!
This and other posts on Meeting C++ are enabled by my supporters on patreon!