Skip to content

Issue with escaping apostrophes #56

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

Closed
ghiculescu opened this issue Feb 12, 2013 · 0 comments
Closed

Issue with escaping apostrophes #56

ghiculescu opened this issue Feb 12, 2013 · 0 comments

Comments

@ghiculescu
Copy link
Contributor

Similar to #54. I'm making an organisation chart, based on the code at http://googlevisualr.herokuapp.com/examples/interactive/org_chart, but the users are being set dynamically so I'm using string interpolation. This means I have to use apostrophes to set attributes on the HTML tags, though.

org_chart = GoogleVisualr::DataTable.new
org_chart.new_column('string', 'Name')
org_chart.new_column('string', 'Boss')
rows = []
rows << [{v: "Bob", f: 'Bob<div style="color:red; font-style:italic">CEO</div>'}, '']
[{name: "Fred", role: "VP"}, {name: "John", role: "VP"}, {name: "Dave", role: "VP"}].each do |data|
  rows << [{v: data[:name], f: "#{data[:name]}<div style='color:red; font-style:italic'>#{data[:role]}</div>"}, 'Bob']
  # the row above is the culprit
end
org_chart.add_rows(rows)
opts   = { :allowHtml => true }
@chart = GoogleVisualr::Interactive::OrgChart.new(org_chart, opts)

In Chrome, this throws a Uncaught SyntaxError: Unexpected identifier. The javascript looks like this:

Screen Shot 2013-02-12 at 11 49 04 PM

If I add .gsub("'", '"') to the row in question, or if I escape the quotation marks myself, everything renders fine, but it's not very elegant.

I'm using v2.1.6 of the gem.

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