Skip to content

Commit

Permalink
escape html to support <,>, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Mcgowan committed Jan 30, 2009
1 parent 3114145 commit a100556
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/roo/openoffice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'zip/zipfilesystem'
require 'date'
require 'base64'
require 'cgi'

class Openoffice < GenericSpreadsheet

Expand Down Expand Up @@ -304,9 +305,8 @@ def read_cells(sheet=nil)
str_v = str_v + child.to_s #.text
}
end
str_v.gsub!(/&quot;/,'"')
str_v.gsub!(/&amp;/,'&')
str_v.gsub!(/&apos;/,"'")
str_v.gsub!(/&apos;/,"'") # special case not supported by unescapeHTML
str_v = CGI.unescapeHTML(str_v)
end # == 'p'
end
elsif vt == 'time'
Expand Down
2 changes: 1 addition & 1 deletion test/no_spreadsheet_file.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
this is intionally not a spreadsheet file
this is intentionally not a spreadsheet file
13 changes: 13 additions & 0 deletions test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4830,4 +4830,17 @@ def SKIP_test_bug_encoding_exported_from_google
assert_equal 'test', xl.cell(2,'F')
end
end

def test_cell_openoffice_html_escape
if OPENOFFICE
oo = Openoffice.new(File.join("test","html-escape.ods"))
oo.default_sheet = oo.sheets.first
assert_equal "'", oo.cell(1,1)
assert_equal "&", oo.cell(2,1)
assert_equal ">", oo.cell(3,1)
assert_equal "<", oo.cell(4,1)
assert_equal "`", oo.cell(5,1)
# test_openoffice_zipped catches the &quot;
end
end
end # class

0 comments on commit a100556

Please sign in to comment.