|
17 | 17 |
|
18 | 18 | use crate::chrome::{ChromeManager, CHROMEDRIVER_NAME, CHROME_NAME}; |
19 | 19 | use crate::edge::{EdgeManager, EDGEDRIVER_NAME, EDGE_NAMES}; |
20 | | -use crate::files::{ |
21 | | - compose_cache_folder, create_parent_path_if_not_exists, get_binary_extension, |
22 | | - path_buf_to_string, |
23 | | -}; |
| 20 | +use crate::files::{compose_cache_folder, create_parent_path_if_not_exists, get_binary_extension}; |
24 | 21 | use crate::firefox::{FirefoxManager, FIREFOX_NAME, GECKODRIVER_NAME}; |
25 | 22 | use crate::iexplorer::{IExplorerManager, IEDRIVER_NAME, IE_NAMES}; |
26 | 23 | use crate::safari::{SafariManager, SAFARIDRIVER_NAME, SAFARI_NAME}; |
@@ -92,6 +89,7 @@ pub const LF: &str = "\n"; |
92 | 89 | pub const SNAPSHOT: &str = "SNAPSHOT"; |
93 | 90 | pub const OFFLINE_REQUEST_ERR_MSG: &str = "Unable to discover proper {} version in offline mode"; |
94 | 91 | pub const OFFLINE_DOWNLOAD_ERR_MSG: &str = "Unable to download {} in offline mode"; |
| 92 | +pub const UNC_PREFIX: &str = r#"\\?\"#; |
95 | 93 |
|
96 | 94 | pub trait SeleniumManager { |
97 | 95 | // ---------------------------------------------------------- |
@@ -189,15 +187,15 @@ pub trait SeleniumManager { |
189 | 187 | } |
190 | 188 |
|
191 | 189 | if full_browser_path.exists() { |
192 | | - let canon_browser_path = full_browser_path.as_path().canonicalize().unwrap(); |
| 190 | + let canon_browser_path = self.canonicalize_path(full_browser_path); |
193 | 191 | self.get_logger().debug(format!( |
194 | 192 | "{} detected at {}", |
195 | 193 | self.get_browser_name(), |
196 | | - canon_browser_path.display() |
| 194 | + canon_browser_path |
197 | 195 | )); |
198 | | - self.set_browser_path(path_buf_to_string(canon_browser_path.clone())); |
| 196 | + self.set_browser_path(canon_browser_path.clone()); |
199 | 197 |
|
200 | | - Some(canon_browser_path) |
| 198 | + Some(Path::new(&canon_browser_path).to_path_buf()) |
201 | 199 | } else { |
202 | 200 | // Check browser in PATH |
203 | 201 | let browser_name = self.get_browser_name(); |
@@ -617,19 +615,30 @@ pub trait SeleniumManager { |
617 | 615 | } |
618 | 616 | } |
619 | 617 |
|
| 618 | + fn canonicalize_path(&self, path_buf: PathBuf) -> String { |
| 619 | + let canon_path = path_buf |
| 620 | + .as_path() |
| 621 | + .canonicalize() |
| 622 | + .unwrap() |
| 623 | + .to_str() |
| 624 | + .unwrap() |
| 625 | + .to_string(); |
| 626 | + if WINDOWS.is(self.get_os()) { |
| 627 | + canon_path.replace(UNC_PREFIX, "") |
| 628 | + } else { |
| 629 | + canon_path |
| 630 | + } |
| 631 | + } |
| 632 | + |
620 | 633 | fn get_escaped_path(&self, string_path: String) -> String { |
621 | 634 | let original_path = string_path.clone(); |
622 | 635 | let mut escaped_path = string_path; |
623 | 636 | let path = Path::new(&original_path); |
| 637 | + |
624 | 638 | if path.exists() { |
625 | | - escaped_path = Path::new(path) |
626 | | - .canonicalize() |
627 | | - .unwrap() |
628 | | - .to_str() |
629 | | - .unwrap() |
630 | | - .to_string(); |
| 639 | + escaped_path = self.canonicalize_path(path.to_path_buf()); |
631 | 640 | if WINDOWS.is(self.get_os()) { |
632 | | - escaped_path = escaped_path.replace("\\\\?\\", "").replace('\\', "\\\\"); |
| 641 | + escaped_path = escaped_path.replace('\\', "\\\\"); |
633 | 642 | } else { |
634 | 643 | escaped_path = run_shell_command( |
635 | 644 | "bash", |
|
0 commit comments