diff options
| author | Jurriaan Pruis <[email protected]> | 2014-03-04 15:49:45 +0100 |
|---|---|---|
| committer | Jurriaan Pruis <[email protected]> | 2014-03-04 15:49:45 +0100 |
| commit | e8ec96f28c69443ce1133ccb7d60d0019669623e (patch) | |
| tree | 80de7d7697ac9d519c2ec3aa71b1022e5a8715ce /lib | |
| parent | 2bee5b68dd51f397e5b39cdf52a5801bc863dbab (diff) | |
| parent | a4853cdac7e777cb3939920c3c6b2862547e4b03 (diff) | |
| download | caxlsx-e8ec96f28c69443ce1133ccb7d60d0019669623e.tar.gz caxlsx-e8ec96f28c69443ce1133ccb7d60d0019669623e.zip | |
Merge pull request #294 from jurriaan/richtext-fixes
Fix sanitizing and some cleanup
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/rich_text.rb | 21 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/rich_text_run.rb | 8 |
2 files changed, 17 insertions, 12 deletions
diff --git a/lib/axlsx/workbook/worksheet/rich_text.rb b/lib/axlsx/workbook/worksheet/rich_text.rb index 18c8e6b5..43f18299 100644 --- a/lib/axlsx/workbook/worksheet/rich_text.rb +++ b/lib/axlsx/workbook/worksheet/rich_text.rb @@ -1,32 +1,35 @@ module Axlsx - class RichText + class RichText < SimpleTypedList def initialize(text = nil, options={}) - @runs = SimpleTypedList.new(RichTextRun) - add_run(text, options) unless text.nil? - yield self if block_given? + super(RichTextRun) + add_run(text, options) unless text.nil? + yield self if block_given? end attr_reader :runs - attr_reader :cell def cell=(cell) @cell = cell - @runs.each { |run| run.cell = cell } + each { |run| run.cell = cell } end def autowidth widtharray = [0] # Are arrays the best way of solving this problem? - @runs.each { |run| run.autowidth(widtharray) } + each { |run| run.autowidth(widtharray) } widtharray.max end def add_run(text, options={}) - @runs << RichTextRun.new(text, options) + self << RichTextRun.new(text, options) + end + + def runs + self end def to_xml_string(str='') - runs.each{ |run| run.to_xml_string(str) } + each{ |run| run.to_xml_string(str) } str end end diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 69063135..e91514ed 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -3,7 +3,7 @@ module Axlsx include Axlsx::OptionsParser - attr_accessor :value + attr_reader :value INLINE_STYLES = [:font_name, :charset, :family, :b, :i, :strike, :outline, @@ -15,6 +15,10 @@ module Axlsx parse_options(options) end + def value=(value) + @value = Axlsx::trust_input ? value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(value.to_s)) + end + attr_accessor :cell # The inline font_name property for the cell @@ -122,7 +126,6 @@ module Axlsx # @param [String] v The 8 character representation for an rgb color #FFFFFFFF" def color=(v) @color = v.is_a?(Color) ? v : Color.new(:rgb=>v) - @is_text_run = true end # The inline sz property for the cell @@ -187,7 +190,6 @@ module Axlsx return unless INLINE_STYLES.include?(attr.to_sym) Axlsx.send(validator, value) unless validator.nil? self.instance_variable_set :"@#{attr.to_s}", value - @is_text_run = true end def to_xml_string(str = '') |
