Project

General

Profile

Actions

Feature #7854

closed

New method Symbol[string]

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

Status:
Closed
Target version:
[ruby-core:52267]

Description

I propose a new class method [] on Symbol. If a symbol s already exists such that s.to_s == string, then s is returned. If not, nil is returned.

The inspiration for this method is a question I was asked, and the answer I was given: "Why would you want to turn a tainted string into a symbol?" "I don't--I want to access an existing symbol with tainted data". Symbol[] accesses the symbol table like hash[] accesses the elements of a hash.

I believe that this completely addresses the problems behind tickets #7791 and #7839. I believe that it is a more intuitive solution than my proposal #7795, and I believe that this will also be useful for YAML.safe_load and similar initiatives.


Files

symbol_lookup.patch (1.83 KB) symbol_lookup.patch phluid61 (Matthew Kerwin), 03/07/2013 12:50 PM
symbol_lookup2.patch (1.36 KB) symbol_lookup2.patch phluid61 (Matthew Kerwin), 03/08/2013 08:48 AM
symbol_lookup3.patch (1.07 KB) symbol_lookup3.patch phluid61 (Matthew Kerwin), 03/09/2013 05:54 PM
symbol_lookup3_warn.patch (1.16 KB) symbol_lookup3_warn.patch phluid61 (Matthew Kerwin), 03/09/2013 05:54 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #7839: Symbol.freeze_symbolsRejectedmatz (Yukihiro Matsumoto)02/13/2013Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0