Skip to content

Commit

Permalink
Added a quick test to show the failing text escaping and a hackish pa…
Browse files Browse the repository at this point in the history
…tch just for legends

Signed-off-by: Matt Aimonetti <mattaimonetti@gmail.com>
  • Loading branch information
der-flo authored and mattetti committed Jun 12, 2009
1 parent 9bbcff3 commit caa3378
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/gchart.rb
Expand Up @@ -3,6 +3,7 @@
require 'gchart/theme'
require "open-uri"
require "uri"
require "cgi"

class Gchart

Expand Down Expand Up @@ -238,7 +239,7 @@ def set_legend
return set_labels if @type == :pie || @type == :pie_3d || @type == :meter

if @legend.is_a?(Array)
"chdl=#{@legend.map{|label| "#{label}"}.join('|')}"
"chdl=#{@legend.map{|label| "#{CGI::escape(label)}"}.join('|')}"
else
"chdl=#{@legend}"
end
Expand Down
7 changes: 7 additions & 0 deletions spec/gchart_spec.rb
Expand Up @@ -227,6 +227,13 @@
@chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true
end

it "should escape text values in url" do
title = 'Chart & Title'
legend = ['first data & set label', 'n data set label']
chart = Gchart.line(:title => title, :legend => legend)
chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true
end

it "should be able to have one legend" do
chart = Gchart.line(:legend => 'legend label')
chart.include?("chdl=legend+label").should be_true
Expand Down

0 comments on commit caa3378

Please sign in to comment.