mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-04-28 23:06:41 +02:00
refactor: handle space in the user name
This commit is contained in:
@@ -244,16 +244,22 @@ pub fn enable_autostart() -> io::Result<()> {
|
||||
|
||||
let desktop_path = autostart_dir.join("donut-daemon.desktop");
|
||||
|
||||
let escaped_daemon_path = daemon_path
|
||||
.display()
|
||||
.to_string()
|
||||
.replace('\\', "\\\\")
|
||||
.replace('"', "\\\"")
|
||||
.replace('`', "\\`")
|
||||
.replace('$', "\\$");
|
||||
let desktop_content = format!(
|
||||
r#"[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Donut Browser Daemon
|
||||
Exec={} run
|
||||
Exec="{escaped_daemon_path}" run
|
||||
Hidden=false
|
||||
NoDisplay=true
|
||||
X-GNOME-Autostart-enabled=true
|
||||
"#,
|
||||
daemon_path.display()
|
||||
);
|
||||
|
||||
fs::write(&desktop_path, desktop_content)?;
|
||||
|
||||
@@ -204,7 +204,7 @@ mod windows {
|
||||
.map_err(|e| format!("Failed to set ApplicationDescription: {}", e))?;
|
||||
|
||||
app_key
|
||||
.set_value("ApplicationIcon", &format!("{},0", exe_path))
|
||||
.set_value("ApplicationIcon", &format!("\"{}\",0", exe_path))
|
||||
.map_err(|e| format!("Failed to set ApplicationIcon: {}", e))?;
|
||||
|
||||
// Create Capabilities key
|
||||
@@ -273,7 +273,7 @@ mod windows {
|
||||
.map_err(|e| format!("Failed to create DefaultIcon key: {}", e))?;
|
||||
|
||||
icon_key
|
||||
.set_value("", &format!("{},0", exe_path))
|
||||
.set_value("", &format!("\"{}\",0", exe_path))
|
||||
.map_err(|e| format!("Failed to set default icon: {}", e))?;
|
||||
|
||||
// Create shell\open\command key
|
||||
|
||||
@@ -1682,9 +1682,11 @@ impl ProfileManager {
|
||||
let pac_content = "function FindProxyForURL(url, host) { return 'DIRECT'; }";
|
||||
let pac_path = uuid_dir.join("proxy.pac");
|
||||
fs::write(&pac_path, pac_content)?;
|
||||
let pac_url =
|
||||
url::Url::from_file_path(&pac_path).map_err(|_| "Failed to convert PAC path to file URL")?;
|
||||
preferences.push(format!(
|
||||
"user_pref(\"network.proxy.autoconfig_url\", \"file://{}\");",
|
||||
pac_path.to_string_lossy()
|
||||
"user_pref(\"network.proxy.autoconfig_url\", \"{}\");",
|
||||
pac_url.as_str()
|
||||
));
|
||||
|
||||
fs::write(user_js_path, preferences.join("\n"))?;
|
||||
@@ -1843,6 +1845,33 @@ mod tests {
|
||||
"Should set SSL proxy port"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pac_url_encodes_spaces_in_path() {
|
||||
let (manager, temp_dir) = create_test_profile_manager();
|
||||
|
||||
let uuid_dir = temp_dir.path().join("path with spaces");
|
||||
let profile_dir = uuid_dir.join("profile");
|
||||
fs::create_dir_all(&profile_dir).expect("Should create profile directory");
|
||||
|
||||
let result = manager.disable_proxy_settings_in_profile(&profile_dir);
|
||||
assert!(result.is_ok(), "Should handle paths with spaces");
|
||||
|
||||
let user_js = fs::read_to_string(profile_dir.join("user.js")).unwrap();
|
||||
let pac_line = user_js
|
||||
.lines()
|
||||
.find(|l| l.contains("autoconfig_url"))
|
||||
.expect("Should have autoconfig_url preference");
|
||||
|
||||
assert!(
|
||||
!pac_line.contains("path with spaces"),
|
||||
"PAC URL should not contain raw spaces: {pac_line}"
|
||||
);
|
||||
assert!(
|
||||
pac_line.contains("path%20with%20spaces"),
|
||||
"PAC URL should percent-encode spaces: {pac_line}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
||||
Reference in New Issue
Block a user