Skip to content

Commit ee99242

Browse files
committed
limit HTML encoder span_for_kinds cache size
1 parent 05f5a0e commit ee99242

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/coderay/encoders/html.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ def style_for_kinds kinds
284284
end
285285

286286
def make_span_for_kinds method, hint
287-
# FIXME: cache attack
288287
Hash.new do |h, kinds|
289-
h[kinds] = begin
288+
begin
290289
css_class = css_class_for_kinds(kinds)
291290
title = HTML.token_path_to_hint hint, kinds if hint
292291

@@ -298,6 +297,9 @@ def make_span_for_kinds method, hint
298297
"<span#{title}#{" class=\"#{css_class}\"" if css_class}>"
299298
end
300299
end
300+
end.tap do |span|
301+
h.clear if h.size >= 100
302+
h[kinds] = span
301303
end
302304
end
303305
end

0 commit comments

Comments
 (0)