summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xAB <0xAB@protonmail.com>2017-09-02 16:41:30 +0100
committer0xAB <0xAB@protonmail.com>2017-09-02 16:41:30 +0100
commitf177c95b13c4d702c145885d8fe611abbe603d6b (patch)
tree4b584d80bd54f3ac8d5d511d51935805ee4534de
parent638ad6b30e29af1993007d331f40682b7d714613 (diff)
downloadpry-backup-master.tar.gz
displayable_string? improvementsmaster-backup-18-oct-2017backup-master
-rw-r--r--lib/pry/helpers/text.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb
index 8fbd992f..ba675304 100644
--- a/lib/pry/helpers/text.rb
+++ b/lib/pry/helpers/text.rb
@@ -79,17 +79,20 @@ class Pry
# @see #displayable_character?
#
def displayable_string?(str)
- require 'open3' if not defined?(Open3)
- variables = {
- str: str,
- impl_specific_options: jruby? ? "--dev --client --disable=gems --disable=did_you_mean" : ""
- }
- args = Shellwords.shellsplit(DISPLAY_CMD % variables)
- Open3.popen3({}, [RbConfig.ruby, "pry-#{__method__}"], *args) do |_,out,_,_|
- str == out.gets.chomp
+ str = str.to_s
+ case
+ # Assume all terminals support ASCII, mostly an optimisation for JRuby.
+ when str.ascii_only? then true
+ else
+ variables = {str: Base64.strict_encode64(Marshal.dump(str)), # make sure "str" is not eval'ed.
+ impl_opts: jruby? ? "--dev --client --disable=gems --disable=did_you_mean" : ""}
+ args = Shellwords.shellsplit(DISPLAY_CMD % variables)
+ Open3.popen3({}, [RbConfig.ruby, "pry-#{__method__}"], *args) {|_,out,_,_| str == out.gets.to_s.chomp}
end
end
- DISPLAY_CMD = %q(%{impl_specific_options} --disable-gems -e 'print "%{str}"').freeze
+ require 'base64'
+ require 'open3'
+ DISPLAY_CMD = %q(%{impl_opts} --disable-gems -rbase64 -e 'print Marshal.load(Base64.strict_decode64("%{str}"))').freeze
SNOWMAN = "☃".freeze
private_constant :DISPLAY_CMD, :SNOWMAN