From 84fb03190a7855c428cb69578d444b367a85ad39 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Tue, 11 Jun 2019 09:59:14 -0700 Subject: [PATCH] Implement PR #131 for Edge --- lib/webdrivers/edge_finder.rb | 13 +++++++++---- spec/webdrivers/edgedriver_spec.rb | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/webdrivers/edge_finder.rb b/lib/webdrivers/edge_finder.rb index 1de7ff83..c27dd5fa 100644 --- a/lib/webdrivers/edge_finder.rb +++ b/lib/webdrivers/edge_finder.rb @@ -5,7 +5,7 @@ class EdgeFinder class << self def version location = Selenium::WebDriver::EdgeChrome.path || send("#{System.platform}_location") - version = send("#{System.platform}_version", location) + version = send("#{System.platform}_version", System.escape_path(location)) raise VersionError, 'Failed to find Edge binary or its version.' if version.nil? || version.empty? @@ -21,7 +21,12 @@ def win_location directories.each do |dir| envs.each do |root| option = "#{ENV[root]}\\#{dir}\\#{file}" - return option if File.exist?(option) + next unless File.exist?(option) + + # Escape space and parenthesis with backticks. + option = option.gsub(/([\s()])/, '`\1') if RUBY_PLATFORM == 'java' + + return option end end end @@ -49,11 +54,11 @@ def win_version(location) end def linux_version(location) - System.call("#{Shellwords.escape location} --product-version")&.strip + System.call("#{location} --product-version")&.strip end def mac_version(location) - System.call("#{Shellwords.escape location} --version")&.strip + System.call("#{location} --version")&.strip end end end diff --git a/spec/webdrivers/edgedriver_spec.rb b/spec/webdrivers/edgedriver_spec.rb index d4618e68..7d9f4f5a 100644 --- a/spec/webdrivers/edgedriver_spec.rb +++ b/spec/webdrivers/edgedriver_spec.rb @@ -254,7 +254,9 @@ describe '#driver_path' do it 'returns full location of binary' do - expect(edgedriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/msedgedriver") + expected_bin = "msedgedriver#{'.exe' if Selenium::WebDriver::Platform.windows?}" + expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/#{expected_bin}") + expect(edgedriver.driver_path).to eq(expected_path) end end end