social-share-button icon indicating copy to clipboard operation
social-share-button copied to clipboard

Escape html for description

Open beagleknight opened this issue 7 years ago • 1 comments

Hi there!

We are currently using this gem in our project https://github.com/AjuntamentdeBarcelona/decidim and we found a bug when having descriptions with single quotes in the description like s'explicarà.

I checked your gem and I see you are using html_escape for the title but not for the description. I just want to know if this is intended or not 😄

Thanks!

beagleknight avatar Mar 15 '17 10:03 beagleknight

Anybody who comes down this line trying to truncate description for whatever use and breaking the the layout for one way or another, the solution I implemented was via nokogiri:

def social_share_description(description)
  doc = Nokogiri::HTML::DocumentFragment.parse(description)
    
  doc.search('br').remove
  doc.to_html
end

This sample strips off all the br tags, irregardless if they are written in <br>, <br />, <br >. You might need to require 'nokogiri'.

jcuervo avatar Nov 28 '18 02:11 jcuervo