mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	parse.y: allow junk attrset
* parse.y (rb_id_attrset, intern_str): allow junk attrset ID for Struct. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									5a48805be8
								
							
						
					
					
						commit
						6496dc892d
					
				
					 3 changed files with 12 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,7 @@
 | 
			
		|||
Sun Sep 29 22:56:31 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 | 
			
		||||
Sun Sep 29 23:45:42 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* parse.y (rb_id_attrset, intern_str): allow junk attrset ID for
 | 
			
		||||
	  Struct.
 | 
			
		||||
 | 
			
		||||
	* parse.y (rb_id_attrset): fix inconsistency with literals, allow
 | 
			
		||||
	  ID_ATTRSET and return it itself, but ID_JUNK cannot make ID_ATTRSET.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								parse.y
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								parse.y
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -8895,7 +8895,7 @@ rb_id_attrset(ID id)
 | 
			
		|||
	int scope = (int)(id & ID_SCOPE_MASK);
 | 
			
		||||
	switch (scope) {
 | 
			
		||||
	  case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
 | 
			
		||||
	  case ID_CONST: case ID_CLASS:
 | 
			
		||||
	  case ID_CONST: case ID_CLASS: case ID_JUNK:
 | 
			
		||||
	    break;
 | 
			
		||||
	  case ID_ATTRSET:
 | 
			
		||||
	    return id;
 | 
			
		||||
| 
						 | 
				
			
			@ -10541,7 +10541,7 @@ intern_str(VALUE str)
 | 
			
		|||
    }
 | 
			
		||||
    if (name[last] == '=') {
 | 
			
		||||
	/* attribute assignment */
 | 
			
		||||
	if (!rb_enc_symname2_p(name, last, enc))
 | 
			
		||||
	if (last > 1 && name[last-1] == '=')
 | 
			
		||||
	    goto junk;
 | 
			
		||||
	id = rb_intern3(name, last, enc);
 | 
			
		||||
	if (id > tLAST_OP_ID && !is_attrset_id(id)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,16 +82,16 @@ module Test_Symbol
 | 
			
		|||
      assert_symtype("@foo=", :attrset?)
 | 
			
		||||
      assert_symtype("@@foo=", :attrset?)
 | 
			
		||||
      assert_symtype("$foo=", :attrset?)
 | 
			
		||||
      assert_not_symtype("0=", :attrset?)
 | 
			
		||||
      assert_not_symtype("@=", :attrset?)
 | 
			
		||||
      assert_not_symtype("@@=", :attrset?)
 | 
			
		||||
      assert_symtype("0=", :attrset?)
 | 
			
		||||
      assert_symtype("@=", :attrset?)
 | 
			
		||||
      assert_symtype("@@=", :attrset?)
 | 
			
		||||
      assert_not_symtype("foo", :attrset?)
 | 
			
		||||
      assert_not_symtype("Foo", :attrset?)
 | 
			
		||||
      assert_not_symtype("@foo", :attrset?)
 | 
			
		||||
      assert_not_symtype("@@foo", :attrset?)
 | 
			
		||||
      assert_not_symtype("$foo", :attrset?)
 | 
			
		||||
      assert_not_symtype("[foo]", :attrset?)
 | 
			
		||||
      assert_not_symtype("[foo]=", :attrset?)
 | 
			
		||||
      assert_symtype("[foo]=", :attrset?)
 | 
			
		||||
      assert_equal(:"foo=", Bug::Symbol.attrset("foo"))
 | 
			
		||||
      assert_symtype(Bug::Symbol.attrset("foo"), :attrset?)
 | 
			
		||||
      assert_equal(:"Foo=", Bug::Symbol.attrset("Foo"))
 | 
			
		||||
| 
						 | 
				
			
			@ -102,7 +102,8 @@ module Test_Symbol
 | 
			
		|||
      assert_symtype(Bug::Symbol.attrset("@@foo"), :attrset?)
 | 
			
		||||
      assert_equal(:"$foo=", Bug::Symbol.attrset("$foo"))
 | 
			
		||||
      assert_symtype(Bug::Symbol.attrset("$foo"), :attrset?)
 | 
			
		||||
      assert_raise(NameError) {Bug::Symbol.attrset("[foo]")}
 | 
			
		||||
      assert_equal(:"[foo]=", Bug::Symbol.attrset("[foo]"))
 | 
			
		||||
      assert_symtype(Bug::Symbol.attrset("[foo]"), :attrset?)
 | 
			
		||||
      assert_equal(:[]=, Bug::Symbol.attrset(:[]))
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue