From 5bd9456a33e359c1959b524512394a24122b15cf Mon Sep 17 00:00:00 2001 From: Xanders Date: Sat, 25 Jul 2020 02:42:11 +0300 Subject: [PATCH 1/3] fix (windows): convert incorrect filesystem encoding before use --- lib/pry/code/code_file.rb | 4 ++-- lib/pry/commands/shell_command.rb | 2 +- lib/pry/commands/whereami.rb | 2 +- lib/pry/prompt.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pry/code/code_file.rb b/lib/pry/code/code_file.rb index c079ce7d1..bd447ab5f 100644 --- a/lib/pry/code/code_file.rb +++ b/lib/pry/code/code_file.rb @@ -31,7 +31,7 @@ class CodeFile # Store the current working directory. This allows show-source etc. to work if # your process has changed directory since boot. [Issue #675] - INITIAL_PWD = Dir.pwd + INITIAL_PWD = Dir.pwd.encode('UTF-8') # @return [Symbol] The type of code stored in this wrapper. attr_reader :code_type @@ -98,7 +98,7 @@ def type_from_filename(filename, default = :unknown) # @return [String] def from_pwd - File.expand_path(@filename, Dir.pwd) + File.expand_path(@filename, Dir.pwd.encode('UTF-8')) end # @return [String] diff --git a/lib/pry/commands/shell_command.rb b/lib/pry/commands/shell_command.rb index 6069a8827..7e2afa538 100644 --- a/lib/pry/commands/shell_command.rb +++ b/lib/pry/commands/shell_command.rb @@ -41,7 +41,7 @@ def parse_destination(dest) end def process_cd(dest) - state.old_pwd = Dir.pwd + state.old_pwd = Dir.pwd.encode('UTF-8') Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest)) rescue Errno::ENOENT raise CommandError, "No such directory: #{dest}" diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index f18026e44..aa84b5aff 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -86,7 +86,7 @@ def bad_option_combination? end def location - "#{@file}:#{@line} #{@method && @method.name_with_owner}" + "#{@file.encode('UTF-8')}:#{@line} #{@method && @method.name_with_owner}" end def process diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb index 656e4e2e3..52f48d7cb 100644 --- a/lib/pry/prompt.rb +++ b/lib/pry/prompt.rb @@ -200,7 +200,7 @@ def [](key) "%s %s:%s %s ", name: pry_instance.config.prompt_name, context: Pry.view_clip(context), - pwd: Dir.pwd, + pwd: Dir.pwd.encode('UTF-8'), separator: sep ) end From dd3eb81dea2edf214b1f199f434a604eaf50bc8e Mon Sep 17 00:00:00 2001 From: Xanders Date: Sun, 29 Nov 2020 01:58:05 +0300 Subject: [PATCH 2/3] fix (windows): convert incorrect filesystem encoding on `source_file` method --- lib/pry/commands/reload_code.rb | 2 +- lib/pry/commands/show_info.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pry/commands/reload_code.rb b/lib/pry/commands/reload_code.rb index 85f4260d9..25a125bff 100644 --- a/lib/pry/commands/reload_code.rb +++ b/lib/pry/commands/reload_code.rb @@ -64,7 +64,7 @@ def check_for_reloadability(code_object, identifier) raise CommandError, "Cannot reload #{identifier} as it has no associated file on disk. " \ - "File found was: #{code_object.source_file}" + "File found was: #{code_object.source_file.encode('UTF-8')}" end end diff --git a/lib/pry/commands/show_info.rb b/lib/pry/commands/show_info.rb index 9037cc1f8..3284221d8 100644 --- a/lib/pry/commands/show_info.rb +++ b/lib/pry/commands/show_info.rb @@ -85,7 +85,7 @@ def content_and_headers_for_all_module_candidates(mod) candidate = mod.candidate(v) begin result += "\nCandidate #{v + 1}/#{mod.number_of_candidates}: " \ - "#{candidate.source_file}:#{candidate.source_line}\n" + "#{candidate.source_file.encode('UTF-8')}:#{candidate.source_line}\n" content = content_for(candidate) result += "Number of lines: #{content.lines.count}\n\n" + content @@ -107,7 +107,7 @@ def header(code_object) file_name, line_num = file_and_line_for(code_object) content = content_for(code_object) - h = "\n#{bold('From:')} #{file_name}" + h = "\n#{bold('From:')} #{file_name.encode('UTF-8')}" h += code_object_header(code_object, line_num) h += "\n#{bold('Number of lines:')} " + "#{content.lines.count}\n\n" if @used_super From 3a5b3eb110520994917f302cc029f6d54b4df81b Mon Sep 17 00:00:00 2001 From: Xanders Date: Sun, 29 Nov 2020 02:27:40 +0300 Subject: [PATCH 3/3] fix (windows): correct rubocop warning after encoding fix --- lib/pry/commands/show_info.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pry/commands/show_info.rb b/lib/pry/commands/show_info.rb index 3284221d8..9ccdfd249 100644 --- a/lib/pry/commands/show_info.rb +++ b/lib/pry/commands/show_info.rb @@ -84,8 +84,9 @@ def content_and_headers_for_all_module_candidates(mod) mod.number_of_candidates.times do |v| candidate = mod.candidate(v) begin + safe_file_name = candidate.source_file.encode('UTF-8') result += "\nCandidate #{v + 1}/#{mod.number_of_candidates}: " \ - "#{candidate.source_file.encode('UTF-8')}:#{candidate.source_line}\n" + "#{safe_file_name}:#{candidate.source_line}\n" content = content_for(candidate) result += "Number of lines: #{content.lines.count}\n\n" + content