diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2013-08-23 06:03:29 -0700 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2013-08-23 06:03:29 -0700 |
commit | d9ee8379543c59e75e39a7a233df6639ee7d4160 (patch) | |
tree | b3b4ab995e8270cdce5453c35378c5619670fb17 /lib/coderay/encoders/html.rb | |
parent | 21d07b305f6293065cf08134cee2c66e727422cf (diff) | |
parent | 28c57a5f02ca066e66346a69db1bfe33fc6bfb6e (diff) | |
download | coderay-d9ee8379543c59e75e39a7a233df6639ee7d4160.tar.gz |
Merge pull request #149 from rubychan/fix-cache-attack
Fix Symbol/Cache attacks
Diffstat (limited to 'lib/coderay/encoders/html.rb')
-rw-r--r-- | lib/coderay/encoders/html.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 20f2409..ffde5d2 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -285,7 +285,7 @@ module Encoders def make_span_for_kinds method, hint Hash.new do |h, kinds| - h[kinds.is_a?(Symbol) ? kinds : kinds.dup] = begin + begin css_class = css_class_for_kinds(kinds) title = HTML.token_path_to_hint hint, kinds if hint @@ -297,6 +297,9 @@ module Encoders "<span#{title}#{" class=\"#{css_class}\"" if css_class}>" end end + end.tap do |span| + h.clear if h.size >= 100 + h[kinds] = span end end end @@ -309,8 +312,8 @@ module Encoders def break_lines text, style reopen = '' - @opened.each_with_index do |k, index| - reopen << (@span_for_kinds[index > 0 ? [k, *@opened[0...index]] : k] || '<span>') + @opened.each_with_index do |kind, index| + reopen << (@span_for_kinds[index > 0 ? [kind, *@opened[0...index]] : kind] || '<span>') end text.gsub("\n", "#{'</span>' * @opened.size}#{'</span>' if style}\n#{reopen}#{style}") end |