Skip to content

Commit

Permalink
Ensure to use file_encoding for arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Oct 31, 2020
1 parent 041963a commit 8035dea
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/colorls/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Core
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
Expand All @@ -33,7 +33,7 @@ def initialize(input, all: false, report: false, sort: false, show: false,

init_colors colors

@contents = init_contents(input)
@contents = init_contents(@input)
init_icons
end

Expand Down Expand Up @@ -371,7 +371,7 @@ def tree_branch_preprint(prespace, indent, prespace_icon)
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
Expand Down
68 changes: 68 additions & 0 deletions spec/color_ls/core_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8035dea

Please sign in to comment.