Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows encoding problems #2146

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pry/code/code_file.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/reload_code.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/shell_command.rb
Expand Up @@ -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}"
Expand Down
5 changes: 3 additions & 2 deletions lib/pry/commands/show_info.rb
Expand Up @@ -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}:#{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
Expand All @@ -107,7 +108,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
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/whereami.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/prompt.rb
Expand Up @@ -200,7 +200,7 @@ def [](key)
"%<name>s %<context>s:%<pwd>s %<separator>s ",
name: pry_instance.config.prompt_name,
context: Pry.view_clip(context),
pwd: Dir.pwd,
pwd: Dir.pwd.encode('UTF-8'),
separator: sep
)
end
Expand Down