summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2013-06-23 10:36:03 +0100
committerRandy Morgan <[email protected]>2013-06-23 10:36:03 +0100
commit4954543cc0892008f580f05cfb810fb0986b107f (patch)
tree10d60edecb17725bf2c5e48bac110d2ff3d73638
parentd7ce6f10daad57fc28ca79e10d673f7bc4512673 (diff)
downloadcaxlsx-4954543cc0892008f580f05cfb810fb0986b107f.tar.gz
caxlsx-4954543cc0892008f580f05cfb810fb0986b107f.zip
escape formula for conditional formatting
-rw-r--r--lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb2
-rw-r--r--test/workbook/worksheet/tc_conditional_formatting.rb6
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
index 9db091be..916b31c2 100644
--- a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
+++ b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
@@ -182,7 +182,7 @@ module Axlsx
# @see timePeriod
def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
# @see formula
- def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = v end
+ def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
# @see color_scale
def color_scale=(v)
diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb
index 42e29fa6..9e5e01cf 100644
--- a/test/workbook/worksheet/tc_conditional_formatting.rb
+++ b/test/workbook/worksheet/tc_conditional_formatting.rb
@@ -131,9 +131,11 @@ class TestConditionalFormatting < Test::Unit::TestCase
end
def test_multiple_formulas
- @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1","5"] }
+ @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1 <> 2","5"] }
doc = Nokogiri::XML.parse(@ws.to_xml_string)
- assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1'")
+ p doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']")
+
+ assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1 <> 2'")
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='5'")
end