diff --git a/lib/html-proofer/element.rb b/lib/html-proofer/element.rb index 0119cff3..03ad8b65 100644 --- a/lib/html-proofer/element.rb +++ b/lib/html-proofer/element.rb @@ -181,11 +181,8 @@ def file_path path_dot_ext = path + @check.options[:extension] if @check.options[:assume_extension] base = if absolute_path?(path) # path relative to root - if File.directory?(@check.src) - @check.options[:root_dir] || @check.src - else - @check.options[:root_dir] || File.dirname(@check.src) - end + # either overwrite with root_dir; or, if source is directory, use that; or, just get the current file's dirname + @check.options[:root_dir] || (File.directory?(@check.src) ? @check.src : File.dirname(@check.src)) elsif File.exist?(File.expand_path(path, @check.src)) || File.exist?(File.expand_path(path_dot_ext, @check.src)) # relative links, path is a file File.dirname(@check.path) elsif File.exist?(File.join(File.dirname(@check.path), path)) || File.exist?(File.join(File.dirname(@check.path), path_dot_ext)) # rubocop:disable Lint/DuplicateBranch; relative links in nested dir, path is a file @@ -193,6 +190,7 @@ def file_path else # relative link, path is a directory @check.path end + file = File.join(base, path) if @check.options[:assume_extension] && File.file?("#{file}#{@check.options[:extension]}")