diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb
index 2133ce3..e18ff07 100644
--- a/lib/execjs/external_runtime.rb
+++ b/lib/execjs/external_runtime.rb
@@ -124,7 +124,7 @@ def locate_executable(command)
         commands = Array(command)
         if ExecJS.windows? && File.extname(command) == ""
           ENV['PATHEXT'].split(File::PATH_SEPARATOR).each { |p|
-            commands << (command + p)
+            commands << (command + p.strip)
           }
         end
 
@@ -133,7 +133,7 @@ def locate_executable(command)
             cmd
           else
             path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p|
-              full_path = File.join(p, cmd)
+              full_path = File.join(p.strip, cmd)
               File.executable?(full_path) && File.file?(full_path)
             }
             path && File.expand_path(cmd, path)