mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[win32] Transcode input from console [Bug #18353]
On Windows, as the input from console is encoded in the active code page, convert the input to the internal encoding.
This commit is contained in:
		
							parent
							
								
									0b53a8895f
								
							
						
					
					
						commit
						37cd35aea8
					
				
				
				Notes:
				
					git
				
				2021-12-01 18:54:48 +09:00 
				
			
			
			
		
		
					 1 changed files with 12 additions and 0 deletions
				
			
		
							
								
								
									
										12
									
								
								io.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								io.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -12224,6 +12224,18 @@ rb_stdio_set_default_encoding(void)
 | 
			
		|||
{
 | 
			
		||||
    VALUE val = Qnil;
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
    if (isatty(fileno(stdin))) {
 | 
			
		||||
        rb_encoding *external = rb_locale_encoding();
 | 
			
		||||
        rb_encoding *internal = rb_default_internal_encoding();
 | 
			
		||||
        if (!internal) internal = rb_default_external_encoding();
 | 
			
		||||
        io_encoding_set(RFILE(rb_stdin)->fptr,
 | 
			
		||||
                        rb_enc_from_encoding(external),
 | 
			
		||||
                        rb_enc_from_encoding(internal),
 | 
			
		||||
                        Qnil);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
#endif
 | 
			
		||||
    rb_io_set_encoding(1, &val, rb_stdin);
 | 
			
		||||
    rb_io_set_encoding(1, &val, rb_stdout);
 | 
			
		||||
    rb_io_set_encoding(1, &val, rb_stderr);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue