Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smartquotes break embedded RABL parsing #429

Open
Breefield opened this issue Mar 28, 2013 · 3 comments
Open

Smartquotes break embedded RABL parsing #429

Breefield opened this issue Mar 28, 2013 · 3 comments

Comments

@Breefield
Copy link

I'm rendering a JSON object using a RABL template right into the page (so as not to make additional requests).

:javascript
  var venue = #{render :file => 'api/v1/venues/show', :formats => :json}

Problem is, sometimes smart quotes such as ‘’, or “” are in my user's data. These show up as illegal characters for the javascript parser (I believe they actually break the JSON parser by terminating string prematurely)...however the parsing works fine when I visit the standalone JSON api endpoint (/api/v1/venues/6.json).

My initial thought was to turn config.escape_all_output to true, however this doesn't encode those characters. Any thoughts on how best to escape these characters without adding some kind of find/replace individually for every attribute in my models. Monkeypatch ERB::Util.html_escape perhaps?

@nesquena
Copy link
Owner

nesquena commented Apr 3, 2013

Hmm, yeah I can see how that might be an issue although in properly encoded UTF-8 strings it shouldn't cause any illegal character errors. Check this out: https://github.com/yob/dumb_quotes seems to be an attempt to make fixing this issue easy. I know that the approach isn't ideal, it seems to be an encoding issue of some sort.

@Breefield
Copy link
Author

This gem doesn't work with my version of Rails—a shame. I'll have to figure something else out.

@Breefield
Copy link
Author

Oh turns out it's a NBSP problem. Yuck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants