Skip to content

Commit

Permalink
escape formula for conditional formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
randym committed Jun 23, 2013
1 parent d7ce6f1 commit 4954543
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -182,7 +182,7 @@ def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
# @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)
Expand Down
6 changes: 4 additions & 2 deletions test/workbook/worksheet/tc_conditional_formatting.rb
Expand Up @@ -131,9 +131,11 @@ def test_multiple_formats
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

Expand Down

0 comments on commit 4954543

Please sign in to comment.