diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 3e0ba38a8f..bd02cd3525 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -72,6 +72,7 @@ dependencies = [ "jsonschema", "jsonwebtoken", "log", + "percent-encoding", "regex", "reqwest", "serde", diff --git a/rust/agama-lib/Cargo.toml b/rust/agama-lib/Cargo.toml index 5ca2e37d32..76219dde95 100644 --- a/rust/agama-lib/Cargo.toml +++ b/rust/agama-lib/Cargo.toml @@ -44,6 +44,7 @@ regex = "1.11.1" fluent-uri = { version = "0.3.2", features = ["serde"] } tokio-tungstenite = { version = "0.26.2", features = ["native-tls"] } tokio-native-tls = "0.3.1" +percent-encoding = "2.3.1" [dev-dependencies] httpmock = "0.7.0" diff --git a/rust/agama-lib/src/network/client.rs b/rust/agama-lib/src/network/client.rs index 6f7ab76209..0fb0b6bb30 100644 --- a/rust/agama-lib/src/network/client.rs +++ b/rust/agama-lib/src/network/client.rs @@ -20,6 +20,7 @@ use super::{settings::NetworkConnection, types::Device}; use crate::http::{BaseHTTPClient, BaseHTTPClientError}; +use crate::utils::url::encode; #[derive(Debug, thiserror::Error)] pub enum NetworkClientError { @@ -56,9 +57,10 @@ impl NetworkClient { /// Returns an array of network connections pub async fn connection(&self, id: &str) -> Result { + let encoded_id = encode(id); let json = self .client - .get::(format!("/network/connections/{id}").as_str()) + .get::(format!("/network/connections/{encoded_id}").as_str()) .await?; Ok(json) @@ -70,10 +72,11 @@ impl NetworkClient { connection: NetworkConnection, ) -> Result<(), NetworkClientError> { let id = connection.id.clone(); + let encoded_id = encode(id.as_str()); let response = self.connection(id.as_str()).await; if response.is_ok() { - let path = format!("/network/connections/{id}"); + let path = format!("/network/connections/{encoded_id}"); self.client.put_void(path.as_str(), &connection).await? } else { self.client diff --git a/rust/agama-lib/src/utils.rs b/rust/agama-lib/src/utils.rs index f6fb4f9020..6a98caca59 100644 --- a/rust/agama-lib/src/utils.rs +++ b/rust/agama-lib/src/utils.rs @@ -22,6 +22,7 @@ mod file_format; mod transfer; +pub mod url; pub use file_format::*; pub use transfer::*; diff --git a/rust/agama-lib/src/utils/url.rs b/rust/agama-lib/src/utils/url.rs new file mode 100644 index 0000000000..9d3c8dda4c --- /dev/null +++ b/rust/agama-lib/src/utils/url.rs @@ -0,0 +1,38 @@ +// Copyright (c) [2025] SUSE LLC +// +// All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, contact SUSE LLC. +// +// To contact SUSE LLC about this file by physical or electronic mail, you may +// find current contact information at www.suse.com. + +use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; + +pub fn encode(value: &str) -> String { + utf8_percent_encode(value, NON_ALPHANUMERIC).to_string() +} + +#[cfg(test)] +mod tests { + + use super::encode; + + #[test] + fn test_encode_value() { + let id = "Wired #1"; + let encoded_id = encode(id); + assert_eq!(encoded_id, "Wired%20%231"); + } +} diff --git a/rust/package/agama.changes b/rust/package/agama.changes index e1c7ad342f..d5a9bc4201 100644 --- a/rust/package/agama.changes +++ b/rust/package/agama.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Jul 23 11:37:04 UTC 2025 - Knut Anderssen + +- Fix CLI connection update when using an special character in + the connection ID (bsc#1246930, gh#agama-project/agama#2605). + ------------------------------------------------------------------- Tue Jul 22 07:53:34 UTC 2025 - Martin Vidner