mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-12 05:31:14 +02:00
Properly encode hyperlinks with special characters
This also works on Windows now, since absolute paths include a colon after the drive letter, the `file:` URI needs to start with a triple slash.
This commit is contained in:
parent
76f148cc55
commit
0ad630da4c
4 changed files with 12 additions and 4 deletions
|
@ -61,6 +61,7 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.post_install_message = POST_INSTALL_MESSAGE
|
||||
|
||||
spec.add_runtime_dependency 'addressable', '~> 2.7'
|
||||
spec.add_runtime_dependency 'clocale', '~> 0'
|
||||
spec.add_runtime_dependency 'filesize', '~> 0'
|
||||
spec.add_runtime_dependency 'manpages', '~> 0'
|
||||
|
|
|
@ -8,6 +8,7 @@ require 'io/console'
|
|||
require 'rainbow/ext/string'
|
||||
require 'clocale'
|
||||
require 'unicode/display_width'
|
||||
require 'addressable/uri'
|
||||
|
||||
require 'colorls/core'
|
||||
require 'colorls/fileinfo'
|
||||
|
|
|
@ -377,8 +377,8 @@ module ColorLS
|
|||
end
|
||||
|
||||
def make_link(path, name)
|
||||
href = "file://#{File.absolute_path(path)}/#{name}"
|
||||
"\033]8;;#{href}\007#{name}\033]8;;\007"
|
||||
uri = Addressable::URI.convert_path(File.absolute_path(File.join(path, name)))
|
||||
"\033]8;;#{uri}\007#{name}\033]8;;\007"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -291,9 +291,15 @@ RSpec.describe ColorLS::Flags do
|
|||
context 'with --hyperlink flag' do
|
||||
let(:args) { ['--hyperlink', FIXTURES] }
|
||||
|
||||
href = "file://#{File.absolute_path(FIXTURES)}/a.txt"
|
||||
href = if File::ALT_SEPARATOR.nil?
|
||||
"file://#{File.absolute_path(FIXTURES)}/a.txt"
|
||||
else
|
||||
"file:///#{File.absolute_path(FIXTURES)}/a.txt"
|
||||
end
|
||||
|
||||
it { expect { subject }.to output(include(href)).to_stdout }
|
||||
pattern = File.fnmatch('cat', 'CAT', File::FNM_SYSCASE) ? /#{href}/i : /#{href}/
|
||||
|
||||
it { expect { subject }.to output(match(pattern)).to_stdout }
|
||||
end
|
||||
|
||||
context 'symlinked directory' do
|
||||
|
|
Loading…
Reference in a new issue