Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Tags with Apostrophes Break the Link


Go to End


4 Posts   2903 Views

Avatar
juneallison

Community Member, 110 Posts

19 January 2012 at 10:31am

Hi,

I have a site where I'd like one of the tags to have an apostrophe (ie, What's Cooking). For any normal tag (that has no apostrophe) clicking on the tag will show you all of the posts with that tag. But my tag with the apostrophe won't pull up any results.

Any suggestions for correcting this would be great.

Thanks!

June

Avatar
Willr

Forum Moderator, 5523 Posts

20 January 2012 at 4:03pm

Sounds like a bug - it should encode the tag text to format it using HTML entities (i.e ' for '). If you can, dig down into the template that outputs the tags and find the variable, rather than $Something should be $Something.XML to ensure it's escaped.

Avatar
lexorallan

Community Member, 1 Post

1 February 2012 at 3:35pm

aww

Avatar
SilverDan

Community Member, 5 Posts

7 February 2012 at 12:37pm

Edited: 07/02/2012 1:09pm

It is indeed a bug. I too had this problem with needing to use an apostrophe in a tag. Since single quotes ( ' ) are allowed in URL's, trying to format with htmlentities or urlencode in the controller (or the template $Link.XML method) had no effect on the actual URL being generated by the link.

Instead, I found that the tag code was being converted to it's HTML entity (') prior to the SQL query being run:
In BlogTree_Controller::SelectedTag() (Convert::raw2xml() - BlogTree.php line #300).

My simple solution was to edit BlogTree.php line #300 to remove the raw2xml conversion as below:

return ($this->request->latestParam('Action') == 'tag') ? $this->request->latestParam('ID') : '';

It's perhaps a temporary solution, but it certainly worked for me.

UPDATED

On second thought, it's probably best to keep the raw2xml conversion in the SelectedTag() function, as this function is also used for template output. Instead, edit BlogTree.php line #160 to revert the xml conversion back to raw for the purpose of escaping for the query:

$SQL_tag = Convert::raw2sql(Convert::xml2raw($tag));

This is probably the better solution.