##// END OF EJS Templates
Escape textile titles and styles (#2377)....
Jean-Philippe Lang -
r2168:7776b5b6659e
parent child
Show More
@@ -408,7 +408,7 class RedCloth3 < String
408 # [ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '&#8221;' ], # double closing
408 # [ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '&#8221;' ], # double closing
409 # [ /"/, '&#8220;' ], # double opening
409 # [ /"/, '&#8220;' ], # double opening
410 # [ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
410 # [ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
411 [ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
411 # [ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
412 # [ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
412 # [ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
413 # [ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
413 # [ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
414 # [ /\s->\s/, ' &rarr; ' ], # right arrow
414 # [ /\s->\s/, ' &rarr; ' ], # right arrow
@@ -448,9 +448,12 class RedCloth3 < String
448
448
449 # Search and replace for Textile glyphs (quotes, dashes, other symbols)
449 # Search and replace for Textile glyphs (quotes, dashes, other symbols)
450 def pgl( text )
450 def pgl( text )
451 GLYPHS.each do |re, resub, tog|
451 #GLYPHS.each do |re, resub, tog|
452 next if tog and method( tog ).call
452 # next if tog and method( tog ).call
453 text.gsub! re, resub
453 # text.gsub! re, resub
454 #end
455 text.gsub!(/\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/) do |m|
456 "<acronym title=\"#{htmlesc $2}\">#{$1}</acronym>"
454 end
457 end
455 end
458 end
456
459
@@ -467,7 +470,7 class RedCloth3 < String
467 style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN
470 style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN
468 end
471 end
469
472
470 style << "#{ $1 };" if not filter_styles and
473 style << "#{ htmlesc $1 };" if not filter_styles and
471 text.sub!( /\{([^}]*)\}/, '' )
474 text.sub!( /\{([^}]*)\}/, '' )
472
475
473 lang = $1 if
476 lang = $1 if
@@ -810,7 +813,7 class RedCloth3 < String
810 end
813 end
811 atts = pba( atts )
814 atts = pba( atts )
812 atts = " href=\"#{ url }#{ slash }\"#{ atts }"
815 atts = " href=\"#{ url }#{ slash }\"#{ atts }"
813 atts << " title=\"#{ title }\"" if title
816 atts << " title=\"#{ htmlesc title }\"" if title
814 atts = shelve( atts ) if atts
817 atts = shelve( atts ) if atts
815
818
816 external = (url =~ /^https?:\/\//) ? ' class="external"' : ''
819 external = (url =~ /^https?:\/\//) ? ' class="external"' : ''
@@ -76,6 +76,15 class ApplicationHelperTest < HelperTestCase
76 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
76 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
77 end
77 end
78
78
79 def test_acronyms
80 to_test = {
81 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
82 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
83 }
84 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
85
86 end
87
79 def test_attached_images
88 def test_attached_images
80 to_test = {
89 to_test = {
81 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
90 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
@@ -90,6 +99,7 class ApplicationHelperTest < HelperTestCase
90 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
99 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
91 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
100 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
92 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
101 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
102 '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with &quot;double-quotes&quot;" class="external">link</a>',
93 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
103 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
94 # no multiline link text
104 # no multiline link text
95 "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />\nand another on a second line\":test"
105 "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />\nand another on a second line\":test"
General Comments 0
You need to be logged in to leave comments. Login now