Commit c761e0e4e2f69c0582f64505776facda509171ae

Found a good place (for now) to put the HTML output escaping of diffs

Commit diff

app/helpers/browse_helper.rb

 
8181 out << %Q{<td class="line-numbers">#{dst_sha}</td>}
8282 out << "<td>&nbsp</td></tr>\n"
8383 out << "</thead>\n"
84 out << Diff::Display::Unified::Renderer.run(udiff, callback)
84 out << Diff::Display::Unified::HTMLRenderer.run(udiff, callback)
8585 out << "</table>"
8686 out
8787 end
9393 out << %Q{<colgroup class="right"><col class="lines"/><col class="code"/></colgroup>}
9494 out << %Q{<thead><th colspan="2">#{src_sha}</th>}
9595 out << %Q{<th colspan="2">#{dst_sha}</th></thead>}
96 out << Diff::Display::Unified::Renderer.run(udiff, callback)
96 out << Diff::Display::Unified::HTMLRenderer.run(udiff, callback)
9797 out << "</table>"
9898 out
9999 end
toggle raw diff

lib/gitorious/diff/sidebyside_table_callback.rb

 
5656 def before_remline(line)
5757 # rems go on the left (hide the right side)
5858 %Q{<th class="line-numbers">#{line.number}</th>} +
59 %Q{<td class="code del"><del>#{line}</del></td>} +
59 %Q{<td class="code del"><del>#{CGI.escapeHTML(line)}</del></td>} +
6060 %Q{<th class="line-numbers">#{line.number}</th>} +
6161 %Q{<td class="code del hidden"><del>}
6262 end
6464 def before_modline(line)
6565 # TODO: figure how we best display these
6666 # %Q{<th class="line-numbers">#{line.number}</th>} +
67 # %Q{<td class="code changed mod">#{line}</td>} +
67 # %Q{<td class="code changed mod">#{CGI.escapeHTML(line)}</td>} +
6868 # %Q{<th class="line-numbers">#{line.number}</th>} +
6969 # %Q{<td class="code changed mod">}
7070 end
7272 def before_unmodline(line)
7373 # unmods goes on both sides
7474 %Q{<th class="line-numbers">#{line.number}</th>} +
75 %Q{<td class="code unchanged unmod">#{line}</td>} +
75 %Q{<td class="code unchanged unmod">#{CGI.escapeHTML(line)}</td>} +
7676 %Q{<th class="line-numbers">#{line.number}</th>} +
7777 %Q{<td class="code unchanged unmod">}
7878 end
toggle raw diff

vendor/diff-display/lib/diff/display/unified.rb

 
528528 block_data << before_method(block)
529529 # Block must use braces rather than do/end due to precedence rules!
530530 block_data.concat block.inject([]) { |line_data, line|
531 line_data << before_method(line) << line << after_method(line)
531 line_data << before_method(line) << escape(line) << after_method(line)
532532 }
533533 block_data << after_method(block)
534534 end
543543 new(diff, callback_object).rendered
544544 end
545545 end
546
547 def escape(text)
548 text
549 end
546550
547551 private
548552
619619 end
620620 #:startdoc:#
621621
622 # XXX This doesn't make sense anymore...How to implement a convenient way
623 # to redefine methods such as space and escape?
624 # Mostly a convenience class at this point that just overwrites various
625 # customization methods
626 class HTMLGenerator < Generator #:nodoc:#
622 # Renders with HTML as the target output (only effect is escaped lines)
623 # callbacks will still need to escape any lines they output
624 class HTMLRenderer < Renderer #:nodoc:#
627625
628 # This and the space method now don't work/make sense now that those
629 # methods are part of the Line class and there certainly won't be an
630 # HTMLLine class
626 # escapes
631627 def escape(text)
628 #CGI::escapeHTML(text)
632629 text.gsub('&', '&amp;').
633630 gsub('<', '&lt;' ).
634631 gsub('>', '&gt;' ).
635632 gsub('"', '&#34;')
636633 end
637
638 def space
639 '&nbsp;'
640 end
641
642 end
643
644 # How to implement this? See doc string for HTMLGenerator
645 class ASCIIGenerator < Generator #:nodoc:#
646634 end
647635
648636 end
toggle raw diff