summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-23 10:03:30 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-23 10:03:30 +0000
commit65658ea0d4f17b90bb09003405a7560d6df0b58e (patch)
tree156fdae18505dc97515c157a5ca2bffcdd8482a1
parent2bcd502a71bc0a140f3b78ed0d148745fb648555 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--parse.y2
-rw-r--r--test/ruby/test_symbol.rb13
3 files changed, 20 insertions, 0 deletions
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 <naruse@ruby-lang.org>
+
+ * 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 <akr@fsij.org>
* 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)
[