mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	strscan.c: encoding in messages
* ext/strscan/strscan.c (strscan_aref): preserve argument encoding in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									27c4fb3361
								
							
						
					
					
						commit
						4713ace44c
					
				
					 2 changed files with 7 additions and 10 deletions
				
			
		|  | @ -976,7 +976,7 @@ strscan_matched_size(VALUE self) | |||
| } | ||||
| 
 | ||||
| static int | ||||
| name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end) | ||||
| name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end, rb_encoding *enc) | ||||
| { | ||||
|     int num; | ||||
| 
 | ||||
|  | @ -986,9 +986,8 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name | |||
| 	return num; | ||||
|     } | ||||
|     else { | ||||
| 	VALUE s = rb_str_new(name, (long )(name_end - name)); | ||||
| 	rb_raise(rb_eIndexError, "undefined group name reference: %s", | ||||
| 				 StringValuePtr(s)); | ||||
| 	rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s", | ||||
| 					  rb_long2int(name_end - name), name); | ||||
|     } | ||||
| 
 | ||||
|     UNREACHABLE; | ||||
|  | @ -1033,13 +1032,10 @@ strscan_aref(VALUE self, VALUE idx) | |||
|     switch (TYPE(idx)) { | ||||
|         case T_SYMBOL: | ||||
|             idx = rb_sym2str(idx); | ||||
|             name = RSTRING_PTR(idx); | ||||
|             goto name_to_backref; | ||||
|             break; | ||||
|             /* fall through */ | ||||
|         case T_STRING: | ||||
|             name = StringValuePtr(idx); | ||||
|         name_to_backref: | ||||
| 	    i = name_to_backref_number(&(p->regs), p->regex, name, name + strlen(name)); | ||||
|             RSTRING_GETMEM(idx, name, i); | ||||
|             i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx)); | ||||
|             break; | ||||
|         default: | ||||
|             i = NUM2LONG(idx); | ||||
|  |  | |||
|  | @ -471,6 +471,7 @@ class TestStringScanner < Test::Unit::TestCase | |||
|     assert_equal 'foo', s['a'] | ||||
|     assert_equal 'bar', s['b'] | ||||
|     assert_raise(IndexError) { s['c'] } | ||||
|     assert_raise_with_message(IndexError, /\u{30c6 30b9 30c8}/) { s["\u{30c6 30b9 30c8}"] } | ||||
|   end | ||||
| 
 | ||||
|   def test_pre_match | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 nobu
						nobu