Skip to content

Commit 0267b0f

Browse files
committed
[rust] Remove UNC prefix (for Windows) from canonicalized paths
1 parent d86b1d4 commit 0267b0f

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

rust/src/lib.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
use crate::chrome::{ChromeManager, CHROMEDRIVER_NAME, CHROME_NAME};
1919
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};
2421
use crate::firefox::{FirefoxManager, FIREFOX_NAME, GECKODRIVER_NAME};
2522
use crate::iexplorer::{IExplorerManager, IEDRIVER_NAME, IE_NAMES};
2623
use crate::safari::{SafariManager, SAFARIDRIVER_NAME, SAFARI_NAME};
@@ -92,6 +89,7 @@ pub const LF: &str = "\n";
9289
pub const SNAPSHOT: &str = "SNAPSHOT";
9390
pub const OFFLINE_REQUEST_ERR_MSG: &str = "Unable to discover proper {} version in offline mode";
9491
pub const OFFLINE_DOWNLOAD_ERR_MSG: &str = "Unable to download {} in offline mode";
92+
pub const UNC_PREFIX: &str = r#"\\?\"#;
9593

9694
pub trait SeleniumManager {
9795
// ----------------------------------------------------------
@@ -189,15 +187,15 @@ pub trait SeleniumManager {
189187
}
190188

191189
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);
193191
self.get_logger().debug(format!(
194192
"{} detected at {}",
195193
self.get_browser_name(),
196-
canon_browser_path.display()
194+
canon_browser_path
197195
));
198-
self.set_browser_path(path_buf_to_string(canon_browser_path.clone()));
196+
self.set_browser_path(canon_browser_path.clone());
199197

200-
Some(canon_browser_path)
198+
Some(Path::new(&canon_browser_path).to_path_buf())
201199
} else {
202200
// Check browser in PATH
203201
let browser_name = self.get_browser_name();
@@ -617,19 +615,30 @@ pub trait SeleniumManager {
617615
}
618616
}
619617

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+
620633
fn get_escaped_path(&self, string_path: String) -> String {
621634
let original_path = string_path.clone();
622635
let mut escaped_path = string_path;
623636
let path = Path::new(&original_path);
637+
624638
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());
631640
if WINDOWS.is(self.get_os()) {
632-
escaped_path = escaped_path.replace("\\\\?\\", "").replace('\\', "\\\\");
641+
escaped_path = escaped_path.replace('\\', "\\\\");
633642
} else {
634643
escaped_path = run_shell_command(
635644
"bash",

0 commit comments

Comments
 (0)