Attempt at a bug fix to read backslashes as forward slashes in local fetcher

This commit is contained in:
Annie Hedgpeth 2016-06-29 22:18:30 -05:00 committed by Christoph Hartmann
parent 8825b71412
commit fe5c7c49a4
2 changed files with 28 additions and 23 deletions

View file

@ -15,6 +15,9 @@ module Fetchers
# Support "urls" in the form of file:// # Support "urls" in the form of file://
if target.start_with?('file://') if target.start_with?('file://')
target = target.gsub(%r{^file://}, '') target = target.gsub(%r{^file://}, '')
else
# support for windows paths
target.tr!('\\', '/')
end end
if !File.exist?(target) if !File.exist?(target)

View file

@ -20,38 +20,40 @@ describe Inspec::Plugins::RelFetcher do
let(:src_fetcher) { mock() } let(:src_fetcher) { mock() }
IN_AND_OUT = { IN_AND_OUT = {
[] => [], [] => [],
%w{file} => %w{file}, %w{file} => %w{file},
# don't prefix just by filename # don't prefix just by filename
%w{file file_a} => %w{file file_a}, %w{file file_a} => %w{file file_a},
%w{path/file path/file_a} => %w{file file_a}, %w{path/file path/file_a} => %w{file file_a},
%w{path/to/file} => %w{file}, %w{path/to/file} => %w{file},
%w{/path/to/file} => %w{file}, %w{/path/to/file} => %w{file},
%w{alice bob} => %w{alice bob}, %w{alice bob} => %w{alice bob},
# mixed paths # mixed paths
%w{x/a y/b} => %w{x/a y/b}, %w{x/a y/b} => %w{x/a y/b},
%w{/x/a /y/b} => %w{x/a y/b}, %w{/x/a /y/b} => %w{x/a y/b},
%w{z/x/a z/y/b} => %w{x/a y/b}, %w{z/x/a z/y/b} => %w{x/a y/b},
%w{/z/x/a /z/y/b} => %w{x/a y/b}, %w{/z/x/a /z/y/b} => %w{x/a y/b},
# mixed with relative path # mixed with relative path
%w{a path/to/b} => %w{a path/to/b}, %w{a path/to/b} => %w{a path/to/b},
%w{path/to/b a} => %w{path/to/b a}, %w{path/to/b a} => %w{path/to/b a},
%w{path/to/b path/a} => %w{to/b a}, %w{path/to/b path/a} => %w{to/b a},
%w{path/to/b path/a c} => %w{path/to/b path/a c}, %w{path/to/b path/a c} => %w{path/to/b path/a c},
# mixed with absolute paths # mixed with absolute paths
%w{/path/to/b /a} => %w{path/to/b a}, %w{/path/to/b /a} => %w{path/to/b a},
%w{/path/to/b /path/a} => %w{to/b a}, %w{/path/to/b /path/a} => %w{to/b a},
%w{/path/to/b /path/a /c} => %w{path/to/b path/a c}, %w{/path/to/b /path/a /c} => %w{path/to/b path/a c},
# mixing absolute and relative paths # mixing absolute and relative paths
%w{path/a /path/b} => %w{path/a /path/b}, %w{path/a /path/b} => %w{path/a /path/b},
%w{/path/a path/b} => %w{/path/a path/b}, %w{/path/a path/b} => %w{/path/a path/b},
# extract folder structure buildup # extract folder structure buildup
%w{/a /a/b /a/b/c} => %w{c}, %w{/a /a/b /a/b/c} => %w{c},
%w{/a /a/b /a/b/c/d/e} => %w{e}, %w{/a /a/b /a/b/c/d/e} => %w{e},
# ignore pax_global_header, which are commonly seen in github tars and are not # ignore pax_global_header, which are commonly seen in github tars and are not
# ignored by all tar streaming tools, its not extracted by GNU tar since 1.14 # ignored by all tar streaming tools, its not extracted by GNU tar since 1.14
%w{/pax_global_header /a/b} => %w{b}, %w{/pax_global_header /a/b} => %w{b},
%w{pax_global_header a/b} => %w{b}, %w{pax_global_header a/b} => %w{b},
# windows path
%w{.\\path\\} => %w{./path/}
}.each do |ins, outs| }.each do |ins, outs|
describe 'empty profile' do describe 'empty profile' do
let(:in_files) { ins } let(:in_files) { ins }