From 65658ea0d4f17b90bb09003405a7560d6df0b58e Mon Sep 17 00:00:00 2001 From: naruse Date: Sat, 23 Jul 2011 10:03:30 +0000 Subject: [PATCH] * parse.y (rb_enc_symname_type): :$a!, @a! and so on are not valid symbols, so they should be inspected with quotes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ parse.y | 2 ++ test/ruby/test_symbol.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2dfae8e9a4..b09a912dfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jul 23 15:37:04 2011 NARUSE, Yui + + * parse.y (rb_enc_symname_type): :$a!, @a! and so on are not + valid symbols, so they should be inspected with quotes. + Sat Jul 23 17:06:25 2011 Tanaka Akira * io.c (rb_update_max_fd): validate fd. diff --git a/parse.y b/parse.y index 366090f903..315723287f 100644 --- a/parse.y +++ b/parse.y @@ -9758,10 +9758,12 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc) while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc); switch (*m) { case '!': case '?': + if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1; type = ID_JUNK; ++m; break; case '=': + if (type != ID_CONST && type != ID_LOCAL) return -1; type = ID_ATTRSET; ++m; break; diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 282964cdf5..2a21c78540 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -75,6 +75,19 @@ class TestSymbol < Test::Unit::TestCase assert_inspect_evaled(':$1') end + def test_inspect + valid = %w{$a @a @@a < << <= <=> > >> >= =~ == === * ** + +@ - -@ + | ^ & / % ~ ` [] []= ! != !~ a a? a! a= A A? A! A=} + valid.each do |sym| + assert_equal(':' + sym, sym.intern.inspect) + end + + invalid = %w{$a? $a! $a= @a? @a! @a= @@a? @@a! @@a= =} + invalid.each do |sym| + assert_equal(':"' + sym + '"', sym.intern.inspect) + end + end + def test_to_proc assert_equal %w(1 2 3), (1..3).map(&:to_s) [