Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Tags with Apostrophes Break the Link

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1191 Views
  • juneallison
    Avatar
    Community Member
    108 Posts

    Tags with Apostrophes Break the Link Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Tags with Apostrophes Break the Link Link to this post

    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.

  • lexorallan
    Avatar
    Community Member
    1 Post

    Re: Tags with Apostrophes Break the Link Link to this post

    aww

  • SilverDan
    Avatar
    Community Member
    5 Posts

    Re: Tags with Apostrophes Break the Link Link to this post

    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.

    1191 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.