diff --git a/assets/settings/default.json b/assets/settings/default.json index e0ce02ae2ebc25aa0cd4165315bd381d725923a3..071c84c0005df18045799e5b666971728cad2f8e 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -2235,7 +2235,7 @@ // Examples: // - "proxy": "socks5h://localhost:10808" // - "proxy": "http://127.0.0.1:10809" - "proxy": null, + "proxy": "", // Set to configure aliases for the command palette. // When typing a query which is a key of this object, the value will be used instead. // diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 801c8c3de8d3f02e3d73809df2c651c6973f231a..0d2f36169780751200abc80f88f089d423977984 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -121,7 +121,9 @@ pub struct ProxySettings { impl ProxySettings { pub fn proxy_url(&self) -> Option { self.proxy - .as_ref() + .as_deref() + .map(str::trim) + .filter(|input| !input.is_empty()) .and_then(|input| { input .parse::() @@ -135,7 +137,12 @@ impl ProxySettings { impl Settings for ProxySettings { fn from_settings(content: &settings::SettingsContent) -> Self { Self { - proxy: content.proxy.clone(), + proxy: content + .proxy + .as_deref() + .map(str::trim) + .filter(|proxy| !proxy.is_empty()) + .map(ToOwned::to_owned), } } } @@ -1801,6 +1808,19 @@ mod tests { use settings::SettingsStore; use std::future; + #[test] + fn test_proxy_settings_trims_and_ignores_empty_proxy() { + let mut content = SettingsContent::default(); + content.proxy = Some(" ".to_owned()); + assert_eq!(ProxySettings::from_settings(&content).proxy, None); + + content.proxy = Some("http://127.0.0.1:10809".to_owned()); + assert_eq!( + ProxySettings::from_settings(&content).proxy.as_deref(), + Some("http://127.0.0.1:10809") + ); + } + #[gpui::test(iterations = 10)] async fn test_reconnection(cx: &mut TestAppContext) { init_test(cx); diff --git a/crates/remote_server/src/unix.rs b/crates/remote_server/src/unix.rs index a81859a685e1ce34eccc0a0d4809b9914743f79f..f82a0ae01d58796f0efc41b2acb26939fe0a0990 100644 --- a/crates/remote_server/src/unix.rs +++ b/crates/remote_server/src/unix.rs @@ -953,8 +953,10 @@ fn read_proxy_settings(cx: &mut Context) -> Option { let proxy_str = ProxySettings::get_global(cx).proxy.to_owned(); proxy_str - .as_ref() - .and_then(|input: &String| { + .as_deref() + .map(str::trim) + .filter(|input| !input.is_empty()) + .and_then(|input| { input .parse::() .inspect_err(|e| log::error!("Error parsing proxy settings: {}", e)) diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index 6fb8044e570a5f311ce8fd142f472ceb8b36ac94..e8884e2e02c6d55d44dd30415caa5ceeb11ad3b4 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -6236,20 +6236,16 @@ pub(crate) fn settings_data(cx: &App) -> Vec { title: "Network", items: vec![ SettingsPageItem::SectionHeader("Network"), - // todo(settings_ui): Proxy needs a default SettingsPageItem::SettingItem(SettingItem { title: "Proxy", description: "The proxy to use for network requests.", - field: Box::new( - SettingField { - json_path: Some("proxy"), - pick: |settings_content| settings_content.proxy.as_ref(), - write: |settings_content, value| { - settings_content.proxy = value; - }, - } - .unimplemented(), - ), + field: Box::new(SettingField { + json_path: Some("proxy"), + pick: |settings_content| settings_content.proxy.as_ref(), + write: |settings_content, value| { + settings_content.proxy = value; + }, + }), metadata: Some(Box::new(SettingsFieldMetadata { placeholder: Some("socks5h://localhost:10808"), ..Default::default()