Groklaw RSS feed bug
Thursday, 30 September 2004
While playing around with Firefox’s live bookmarks feature I discovered a small bug in Groklaw’s RSS feed code. Another HTML entities problem…
As you can see in the screenshot above, the title of the story called ‘IBM & SCO File Docs Re SCO’s 2 Expidit…’ is mangled. The & is turned into &. The cause of this problem is actually pretty simple. In valid HTML code, &’s must be written as &
. Usually the function htmlentities()
or function htmlspecialchars()
is used for this purpose. Now, when you run that function twice of the same string you’ll get something like this: &
which is displayed as &.
The solution is pretty simple. Open up lib-common.php
and go to the COM_exportRDF()
function. The line in question looks like this:
$title = '<title>' . htmlspecialchars( stripslashes( $row[$title] )) . "</title>\n";
The value of $row[$title]
is fetched from the database and fed to the htmlspecialchars()
function. Except, the value is already stored in HTML entities format in the database, so the string is converted twice, leading to the problems described above. To fix it, change the line to:
$title = '<title>' . stripslashes( $row[$title] ) . "</title>\n";
RSS feed detection
Another unrelated bug is that the RSS feed of the Groklaw website isn’t automatically detected by FireFox’s live bookmarks feature. The solution to this is also pretty simple. It requires just the addition of a single line inside the HTML template. That single line triggers the live bookmarks feature.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>GROKLAW</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Pragma" content="no-cache">
<link rel="alternate" type="application/xml+rss" title="RSS" href="/backend/GrokLaw.rdf" />
...