From caa337888394c2d17f321c5edeb6d198e200af10 Mon Sep 17 00:00:00 2001 From: Florian Duetsch Date: Thu, 23 Apr 2009 03:09:55 +0800 Subject: [PATCH] Added a quick test to show the failing text escaping and a hackish patch just for legends Signed-off-by: Matt Aimonetti --- lib/gchart.rb | 3 ++- spec/gchart_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/gchart.rb b/lib/gchart.rb index d45f302..60904de 100644 --- a/lib/gchart.rb +++ b/lib/gchart.rb @@ -3,6 +3,7 @@ require 'gchart/theme' require "open-uri" require "uri" +require "cgi" class Gchart @@ -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 diff --git a/spec/gchart_spec.rb b/spec/gchart_spec.rb index 05c99f3..9af2058 100644 --- a/spec/gchart_spec.rb +++ b/spec/gchart_spec.rb @@ -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