mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Issue 284, Pry should respect input encoding.
This commit is contained in:
parent
9b6a08df28
commit
3bb6cd3a31
2 changed files with 20 additions and 0 deletions
|
@ -289,6 +289,13 @@ class Pry
|
|||
Pry.config.control_d_handler.call(eval_string, self)
|
||||
""
|
||||
else
|
||||
|
||||
# Change the eval_string into the input encoding (Issue 284)
|
||||
# TODO: This wouldn't be necessary if the eval_string was constructed from input strings only.
|
||||
if eval_string.empty? && val.respond_to?(:encoding) && val.encoding != eval_string.encoding
|
||||
eval_string.force_encoding(val.encoding)
|
||||
end
|
||||
|
||||
val
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# coding: utf-8
|
||||
require 'helper'
|
||||
|
||||
describe "Pry#input_stack" do
|
||||
|
@ -67,4 +68,16 @@ describe "Pry#input_stack" do
|
|||
str_output.string.should =~ /Error: Pry ran out of things to read/
|
||||
end
|
||||
|
||||
if "".respond_to?(:encoding)
|
||||
it "should pass strings to Pry in the right encoding" do
|
||||
input1 = "'f。。'.encoding.name" # utf-8, see coding declaration
|
||||
input2 = input1.encode('Shift_JIS')
|
||||
|
||||
mock_pry(input1, input2).should == %{=> "UTF-8"\n=> "Shift_JIS"\n\n}
|
||||
end
|
||||
|
||||
it "should be able to use unicode regexes on a UTF-8 terminal" do
|
||||
mock_pry('":-Þ" =~ /\p{Upper}/').should == %{=> 2\n\n}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue