{"id":1000449,"date":"2007-03-17T13:26:57","date_gmt":"2007-03-17T18:26:57","guid":{"rendered":"http:\/\/www.elharo.com\/blog\/software-development\/web-development\/2007\/03\/17\/a-strong-test-for-markup-in-titles-summaries\/"},"modified":"2007-04-13T15:53:21","modified_gmt":"2007-04-13T20:53:21","slug":"a-strong-test-for-markup-in-titles-summaries","status":"publish","type":"post","link":"https:\/\/www.elharo.com\/blog\/software-development\/web-development\/php\/2007\/03\/17\/a-strong-test-for-markup-in-titles-summaries\/","title":{"rendered":"A <strong style=\"color: green\">Strong<\/strong> Test for Markup In Titles &#038; Summaries"},"content":{"rendered":"<p>I&#8217;ve been hacking on Benjamin Smedberg&#8217;s Atom 1.0 plug-in for WordPress. I&#8217;ve added a preference panel for choosing between full text and summary feeds. Now I&#8217;ve fixed the double escaping of content in titles and summaries. (Escaped HTML is <strong>evil<\/strong> and should never have been allowed into Atom.) <\/p>\n<p>However I&#8217;m not sure how my hack will react when posts contain markup in titles and summaries so I&#8217;m playing with that now. Hence this post. I may delete it once I&#8217;m convinced I&#8217;ve covered the various special cases well enough. <\/p>\n<p>Things may look a little funny in the feed until I&#8217;m done since I&#8217;ll be deliberately breaking things to see how WordPress behaves.<br \/>\n<!--more--><\/p>\n<p>So far it seems like WordPress&#8217;s titles are guaranteed to be plain text except for numeric character references. i.e. it strips tags. That&#8217;s good since it will make it easier to use real XHTML in the Atom titles. I need to check if the <code>the_title_rss()<\/code> function really promises that it will never include any tags in the string it returns.<\/p>\n<p>Also it seems I&#8217;ve uncovered a bug in WordPress itself outside the feeds, as this title shows:<\/p>\n<p><code>A &lt;strong style=\"color: green\">Strong&lt;\/strong> Test for Markup In Titles &amp; Summaries<\/code><\/p>\n<p>The bug is in the default theme. I&#8217;m fixing it here and I&#8217;ve reported it to the WordPress folks. To reproduce it yourself, create a post with this string as the title:<\/p>\n<p><code>A <strong style=\"color: green\">Strong<\/strong> Test for Markup In Titles &amp; Summaries<\/code><\/p>\n<p>Publish it and look at what WordPress puts out into the h1 header:<\/p>\n<p><code>&lt;h1 class=\"single\">&lt;a href=\"http:\/\/www.elharo.com\/blog\/software-development\/web-development\/2007\/03\/17\/a-strong-test-for-markup-in-titles-summaries\/\" rel=\"bookmark\" title=\"Permanent Link: A &lt;strong style=\"color: green\">Strong&lt;\/strong> Test for Markup In Titles &amp;amp; Summaries\">A &lt;strong style=\"color: green\">Strong&lt;\/strong> Test for Markup In Titles &amp;amp; Summaries&lt;\/a>&lt;\/h1><\/code><\/p>\n<p><code>the_title_rss()<\/code> function behaves appropriately. The bad text is probably coming from the_title and single_post_title though I haven&#8217;t verified that yet.<\/p>\n<p>WordPress is stuffing the title text (including markup with < and > and &#8220;) into a title attribute without sanitizing it first. I suspect I could reproduce this just by using the &#8221; and > characters in a title without explicitly putting tags into my title.<\/p>\n<p>Arguably this is a theme bug, but it is present in the WordPress default theme. Here&#8217;s the relevant code from the theme:<\/p>\n<p><code>&lt;h2>&lt;a href=\"&lt;?php the_permalink() ?>\" rel=\"bookmark\" title=\"Permanent Link to &lt;?php the_title(); ?>\">&lt;?php the_title(); ?>&lt;\/a>&lt;\/h2><\/code><\/p>\n<p>I&#8217;ve updated my theme code so it no longer shares this bug. To do this, just change <code>Permanent Link to &lt;?php the_title(); ?><\/code> to <code>Permanent Link to &lt;?php the_title()_rss; ?><\/code>. You need to do this in three files, archive.php, single.php and index.php. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been hacking on Benjamin Smedberg&#8217;s Atom 1.0 plug-in for WordPress. I&#8217;ve added a preference panel for choosing between full text and summary feeds. Now I&#8217;ve fixed the double escaping of content in titles and summaries. (Escaped HTML is evil and should never have been allowed into Atom.) However I&#8217;m not sure how my hack [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[410],"class_list":["post-1000449","post","type-post","status-publish","format-standard","hentry","category-php","tag-flash"],"_links":{"self":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1000449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/comments?post=1000449"}],"version-history":[{"count":0,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1000449\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/media?parent=1000449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/categories?post=1000449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/tags?post=1000449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}