update albino to 1.2.3, handle bad code blocks gracefully
This commit is contained in:
+2
-20
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user