Project

General

Profile

Actions

Feature #7795

open

Symbol.defined? and/or to_existing_symbol

Added by Student (Nathan Zook) almost 10 years ago. Updated almost 5 years ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:51965]

Description

I'm pulling this out from deep in the discussions of issue http://bugs.ruby-lang.org/issues/7791, Let Symbols be Garbage Collected.

The problem is that the extreme utility of symbols makes them enticed to use, which results in a DOS vulnerability. My proposal is to add either of a pair of methods that would make it easy to defend against a DOS along these lines.

#1) Symbol.defined?

In existing code, it would might like this:
class Symbol
def self.defined?(string)
all_symbols.any?{|sym| sym.to_s == string}
end
end

#2) to_existing_sym. This would be defined in the same places as to_sym, but would through an argument error if the symbol did not already exist.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0