From 11907e10c73883e5dcdaba11a093ef01c7ee2de8 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 27 Jan 2013 16:26:29 -0500 Subject: v4: check xml representation of characters (& < > in particular) --- lib/sisu/v4/epub_format.rb | 63 ++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'lib/sisu/v4/epub_format.rb') diff --git a/lib/sisu/v4/epub_format.rb b/lib/sisu/v4/epub_format.rb index 84d32000..dd3273d0 100644 --- a/lib/sisu/v4/epub_format.rb +++ b/lib/sisu/v4/epub_format.rb @@ -1217,6 +1217,18 @@ module SiSU_EPUB_Format WOK end end + module SanitizeXML + def self.xml(x) + if x.is_a?(String) + x.gsub(/&/,'&'). + gsub(//,'>'). + #gsub(//,'>'). + gsub(/\\\\/,'
'). + gsub(/<br(?: \/)?>/,'
') + else x + end + end + end class HeadInformation include SiSU_Viz attr_reader :md,:rdf,:vz @@ -1347,10 +1359,12 @@ output_epub_cont_seg.close end def head depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4] + title=SanitizeXML.xml(@md.title.full) + author=SanitizeXML.xml(@md.author) <<-WOK - #{@md.title.full} by #{@md.author} + #{title} by #{author} @@ -1365,16 +1379,18 @@ output_epub_cont_seg.close WOK end def doc_title + txt=SanitizeXML.xml(@md.title.full) <<-WOK - #{@md.title.full} + #{txt} WOK end def doc_author + txt=SanitizeXML.xml(@md.author) <<-WOK - #{@md.author} + #{txt} WOK end @@ -1466,12 +1482,10 @@ output_epub_cont_seg.close m=(m.empty?) \ ? (surname + other_names) : (m + '; ' + surname + ', ' + other_names) - m=m.gsub(//,'>'). - gsub(/<br(?: \/)?>/,';') + m=SanitizeXML.xml(m) end x=@md.creator.author.dup - x=x.gsub(//,'>'). - gsub(/<br(?: \/)?>/,'
') + x=SanitizeXML.xml(x) %{\n #{x}} else '' end @@ -1488,12 +1502,10 @@ output_epub_cont_seg.close m=(m.empty?) \ ? (surname + other_names) : (m + '; ' + surname + ', ' + other_names) - m=m.gsub(//,'>'). - gsub(/<br(?: \/)?>/,';') + m=SanitizeXML.xml(m) end x=@md.creator.editor.dup - x=x.gsub(//,'>'). - gsub(/<br(?: \/)?>/,'
') + x=SanitizeXML.xml(x) %{\n #{x}} else '' end @@ -1510,12 +1522,10 @@ output_epub_cont_seg.close m=(m.empty?) \ ? (surname + other_names) : (m + '; ' + surname + ', ' + other_names) - m=m.gsub(//,'>'). - gsub(/<br(?: \/)?>/,';') + m=SanitizeXML.xml(m) end x=@md.creator.translator.dup - x=x.gsub(//,'>'). - gsub(/<br(?: \/)?>/,'
') + x=SanitizeXML.xml(x) %{\n #{x}} else '' end @@ -1532,28 +1542,24 @@ output_epub_cont_seg.close m=(m.empty?) \ ? (surname + other_names) : (m + '; ' + surname + ', ' + other_names) - m=m.gsub(//,'>'). - gsub(/<br(?: \/)?>/,';') + m=SanitizeXML.xml(m) end x=@md.creator.illustrator.dup - x=x.gsub(//,'>'). - gsub(/<br(?: \/)?>/,'
') + x=SanitizeXML.xml(x) %{\n #{x}} else '' end date_published=if defined? @md.date.published \ and @md.date.published =~/\S+/ x=@md.date.published.dup - x=x.gsub(//,'>'). - gsub(/<br(?: \/)?>/,'
') + x=SanitizeXML.xml(x) %{\n #{x}} else '' end subject=if defined? @md.classify.subject \ and @md.classify.subject =~/\S+/ x=@md.classify.subject.dup - x=x.gsub(//,'>'). - gsub(/<br(?: \/)?>/,'
') + x=SanitizeXML.xml(x) %{\n #{x}} else '' end @@ -1565,7 +1571,7 @@ output_epub_cont_seg.close end rights=if defined? @md.rights.all \ and @md.rights.all =~/\S+/ - rights=@md.rights.all.gsub(/
/,'
') + rights=SanitizeXML.xml(@md.rights.all) %{\n #{rights}} else '' end @@ -1750,9 +1756,8 @@ output_epub_cont_seg.close end def rights def all - rghts=@md.rights.all.gsub(/
/,'
') - rghts=rghts.gsub(/^\s*Copyright\s+\(C\)/,'Copyright © ') - %{

Rights: #{rghts}

} + rights=SanitizeXML.xml(@md.rights.all) + %{

Rights: #{rights}

} end self end @@ -2068,15 +2073,19 @@ output_epub_cont_seg.close #{@vz.table_close}} end def toc_head_copy_at + @txt=SanitizeXML.xml(@txt) %{

#{@txt}

\n} end def center + @txt=SanitizeXML.xml(@txt) %{

#{@txt}

\n} end def bold + @txt=SanitizeXML.xml(@txt) %{

#{@txt}

\n} end def center_bold + @txt=SanitizeXML.xml(@txt) %{

#{@txt}

\n} end end -- cgit v1.2.3