social-share-button
social-share-button copied to clipboard
Escape html for description
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!
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'
.