summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Giuliani <ivan@gocardless.com>2017-05-08 10:00:33 +0100
committerIvan Giuliani <ivan@gocardless.com>2017-05-08 10:09:38 +0100
commit91d8475228b0112b802ab230a20de009a1475973 (patch)
tree6d9d545fccdf8e40da5a09f3702d261ecfaa10ad
parentaddfbaf7d1f0a3c72875c3ddee76af4330b32675 (diff)
downloadhighline-91d8475228b0112b802ab230a20de009a1475973.tar.gz
Do not attempt to change frozen strings
On Ruby 2.3+ string literals are frozen by default. This causes problems in `HighLine::Simulate` since it will try to `.slice!` a frozen string when the default `echo` has been changed.
-rw-r--r--lib/highline/simulate.rb2
-rw-r--r--test/tc_simulator.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/highline/simulate.rb b/lib/highline/simulate.rb
index 3596f59..077d54c 100644
--- a/lib/highline/simulate.rb
+++ b/lib/highline/simulate.rb
@@ -23,7 +23,7 @@ class HighLine
# Simulate StringIO#getbyte by shifting a single character off of the next line of the script
def getbyte
- line = gets
+ line = gets.dup
if line.length > 0
char = line.slice! 0
@strings.unshift line
diff --git a/test/tc_simulator.rb b/test/tc_simulator.rb
index ac81748..a34f63a 100644
--- a/test/tc_simulator.rb
+++ b/test/tc_simulator.rb
@@ -20,4 +20,14 @@ class SimulatorTest < Test::Unit::TestCase
assert_equal '18', age
end
end
+
+ def test_simulate_with_echo_and_frozen_strings
+ HighLine::Simulate.with('the password'.freeze) do
+ password = ask('What is your password?') do |q|
+ q.echo = '*'
+ end
+
+ assert_equal 'the password', password
+ end
+ end
end \ No newline at end of file