update albino to 1.2.3, handle bad code blocks gracefully

This commit is contained in:
rick
2011-01-12 15:00:58 -08:00
parent c5e4935e85
commit 9a4e2e39a8
4 changed files with 16 additions and 30 deletions
+2 -20
View File
@@ -1,30 +1,12 @@
require 'albino'
class Gollum::Albino < Albino
def self.bin
Albino.bin
end
def bin
Albino.bin
end
self.bin = ::Albino.bin
self.default_encoding = ::Albino.default_encoding
def colorize(options = {})
html = super.to_s
html.sub!(%r{</pre></div>\Z}, "</pre>\n</div>")
html
end
# Hotfix for vulnerable versions of Albino
if !instance_methods.include?('shell_escape')
def convert_options(options = {})
@options.merge(options).inject('') do |string, (flag, value)|
string + " -#{flag} #{shell_escape value}"
end
end
def shell_escape(str)
str.to_s.gsub("'", "\\\\'").gsub(";", '\\;')
end
end
end
+8 -4
View File
@@ -380,14 +380,18 @@ module Gollum
@codemap.each do |id, spec|
formatted = spec[:output] || begin
code = spec[:code]
lang = spec[:lang]
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
code.gsub!(/^( |\t)/m, '')
end
formatted = if lang = spec[:lang]
Gollum::Albino.new(code, lang).colorize
else
"<pre><code>#{CGI.escapeHTML(code)}</code></pre>"
formatted = begin
lang && Gollum::Albino.colorize(code, lang)
rescue ::Albino::ShellArgumentError, ::Albino::Process::TimeoutExceeded,
::Albino::Process::MaximumOutputExceeded
end
formatted ||= "<pre><code>#{CGI.escapeHTML(code)}</code></pre>"
update_cache(:code, id, formatted)
formatted
end