diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index 3ab292c..1cee909 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -12,7 +12,7 @@ module ColorLS def initialize(input, all: false, report: false, sort: false, show: false, mode: nil, git_status: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil) - @input = File.absolute_path(input) + @input = (+input).force_encoding(ColorLS.file_encoding) @count = {folders: 0, recognized_files: 0, unrecognized_files: 0} @all = all @almost_all = almost_all @@ -33,7 +33,7 @@ module ColorLS init_colors colors - @contents = init_contents(input) + @contents = init_contents(@input) init_icons end @@ -371,7 +371,7 @@ module ColorLS end def make_link(path, name) - href = "file://#{path}/#{name}" + href = "file://#{File.absolute_path(path)}/#{name}" "\033]8;;#{href}\007#{name}\033]8;;\007" end end diff --git a/spec/color_ls/core_spec.rb b/spec/color_ls/core_spec.rb new file mode 100644 index 0000000..8acea8c --- /dev/null +++ b/spec/color_ls/core_spec.rb @@ -0,0 +1,68 @@ +# coding: utf-8 +require 'spec_helper' + +RSpec.describe ColorLS::Core do + subject { described_class.new(*args) } + + context 'initialize' do + let(:args) { 'Imágenes' } + + it 'works with Unicode characters' do + camera = 'Cámara'.force_encoding(ColorLS::file_encoding) + imagenes = 'Imágenes'.force_encoding(ColorLS::file_encoding) + + dirInfo = instance_double( + 'FileInfo', + :group => "sys", + :mtime => Time.now, + :directory? => true, + :owner => "user", + :name => imagenes, + :show => imagenes, + :nlink => 1, + :size => 128, + :blockdev? => false, + :chardev? => false, + :socket? => false, + :symlink? => false, + :stats => OpenStruct.new( + mode: 0o444, # read for user, owner, other + setuid?: false, + setgid?: false, + sticky?: false + ), + :executable? => true + ) + + fileInfo = instance_double( + 'FileInfo', + :group => "sys", + :mtime => Time.now, + :directory? => false, + :owner => "user", + :name => camera, + :show => camera, + :nlink => 1, + :size => 128, + :blockdev? => false, + :chardev? => false, + :socket? => false, + :symlink? => false, + :stats => OpenStruct.new( + mode: 0o444, # read for user, owner, other + setuid?: false, + setgid?: false, + sticky?: false + ), + :executable? => false + ) + + expect(::Dir).to receive(:entries).and_return([camera]) + + allow(ColorLS::FileInfo).to receive(:new).and_return(dirInfo) + allow(ColorLS::FileInfo).to receive(:new).with(File.join(imagenes, camera), link_info: false) { fileInfo } + + expect { subject }.not_to raise_error + end + end +end