Incorrect encoding for interactive input #843

Closed
Crossverse opened this Issue Feb 6, 2013 · 8 comments

Comments

Projects
None yet
4 participants

GD!

In Pry when i type dd="string" i'll get dd.encoding =>ASCII-8bit and its wrong.

In IRB dd.encoding =>"IBM866" and it 's true.

STDIN.external_encoding in both case =>"IBM866".

  1. Can you resilve problem?
  2. Is it possible to configure default encoding of typed strings in Pry?
Owner

kyrylo commented Feb 20, 2013

Could you provide some information about your environment? Also, I cannot reproduce your bug. Are there any special cases I need to pay attention to?

GD! I have win8 environment. Default windows encoding 'cp1251'. default console encoding 'ibm866'. when i use only latin characters the encoding of strings is 'US-ASCII'. when i use russian symbols i get 'ASCII-8BIT' encoding.

simple way to reproduce encoding following. in pry interactive input.
[1] pry(main)> r="rrr"
=> "rrr"
[2] pry(main)> r.encoding
=> #Encoding:US-ASCII
[3] pry(main)> r="ююю"
=> "\xEE\xEE\xEE"
[4] pry(main)> r.encoding
=> #Encoding:ASCII-8BIT
[5] pry(main)>

It seems that rbreadline return incorrect encoding for non-latin strings. (may be rbreadline work only with latin and some japan encodings)

Contributor

rking commented Feb 20, 2013

Hi! When you refer to the default Windows encoding and default terminal encoding, where is this set? What does it affect? What do you expect Pry to be doing? Does a normal Ruby program respond to those settings?

Thanks!

console ruby programms correctly know external encoding (f.e. ibm866). i expect that encoding of strings with non latin symbols that was input in interactive pry must be 'ibm866'. its worked normal in irb and as i understand it is normal ruby program behaviour (encoding of input strings must be external encoding, but for interactive pry it is not work correctly)

Owner

kyrylo commented Feb 23, 2013

@Crossverse, sorry, but how is that possible that you use Russian letters in IRB or Pry? This is what I get (question marks instead of Russian letters).

Owner

kyrylo commented Feb 23, 2013

@Crossverse, never mind. :-P

I can reproduce the issue.

kyrylo was assigned Feb 24, 2013

Owner

ConradIrwin commented May 10, 2013

The problem is that Readline.readline always returns ASCII strings on windows. You can "hack" a fix with:

Pry.hooks.add_hook :after_read, :hack_encoding do |str, _|
  str.force_encoding STDIN.external_encoding 
end

We should probably file this bug in ruby itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment