From 484893fabe2b17d7b4ccc61738f94e0245dbc1f1 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 24 Jul 2025 13:18:27 +0100 Subject: [PATCH 1/4] Encode connection ID for the URL path --- rust/agama-lib/src/network/client.rs | 7 +++-- rust/agama-lib/src/utils.rs | 1 + rust/agama-lib/src/utils/url.rs | 41 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 rust/agama-lib/src/utils/url.rs diff --git a/rust/agama-lib/src/network/client.rs b/rust/agama-lib/src/network/client.rs index 6f7ab76209..e3a60072c6 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::encoded; #[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 = encoded(id.to_string()); 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 = encoded(id.to_string()); 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..97232b7c8b --- /dev/null +++ b/rust/agama-lib/src/utils/url.rs @@ -0,0 +1,41 @@ +// 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 url::form_urlencoded::byte_serialize; + +pub fn encoded(value: String) -> String { + let serialized_value: String = byte_serialize(value.as_bytes()).collect(); + // Encode space to '%20' as per url standard + // Should be fixed by https://github.com/servo/rust-url/pull/1028 + serialized_value.replace("+", "%20") +} + +#[cfg(test)] +mod tests { + + use super::encoded; + + #[test] + fn test_encode_value() { + let id = "Wired #1"; + let encoded_id = encoded(id.to_string()); + assert_eq!(encoded_id, "Wired%20%231"); + } +} From aa447282bf9627118fe600ea92d261c64a8f4835 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 24 Jul 2025 13:18:51 +0100 Subject: [PATCH 2/4] Added changelog --- rust/package/agama.changes | 6 ++++++ 1 file changed, 6 insertions(+) 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 From 5b874a490a7c23dbb28201f63ebf6360c15e178f Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 24 Jul 2025 13:37:10 +0100 Subject: [PATCH 3/4] Use percent_encoding --- rust/Cargo.lock | 1 + rust/agama-lib/Cargo.toml | 1 + rust/agama-lib/src/network/client.rs | 6 +++--- rust/agama-lib/src/utils/url.rs | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) 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 e3a60072c6..0fb0b6bb30 100644 --- a/rust/agama-lib/src/network/client.rs +++ b/rust/agama-lib/src/network/client.rs @@ -20,7 +20,7 @@ use super::{settings::NetworkConnection, types::Device}; use crate::http::{BaseHTTPClient, BaseHTTPClientError}; -use crate::utils::url::encoded; +use crate::utils::url::encode; #[derive(Debug, thiserror::Error)] pub enum NetworkClientError { @@ -57,7 +57,7 @@ impl NetworkClient { /// Returns an array of network connections pub async fn connection(&self, id: &str) -> Result { - let encoded_id = encoded(id.to_string()); + let encoded_id = encode(id); let json = self .client .get::(format!("/network/connections/{encoded_id}").as_str()) @@ -72,7 +72,7 @@ impl NetworkClient { connection: NetworkConnection, ) -> Result<(), NetworkClientError> { let id = connection.id.clone(); - let encoded_id = encoded(id.to_string()); + let encoded_id = encode(id.as_str()); let response = self.connection(id.as_str()).await; if response.is_ok() { diff --git a/rust/agama-lib/src/utils/url.rs b/rust/agama-lib/src/utils/url.rs index 97232b7c8b..ac1766a786 100644 --- a/rust/agama-lib/src/utils/url.rs +++ b/rust/agama-lib/src/utils/url.rs @@ -18,10 +18,10 @@ // To contact SUSE LLC about this file by physical or electronic mail, you may // find current contact information at www.suse.com. -use url::form_urlencoded::byte_serialize; +use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; -pub fn encoded(value: String) -> String { - let serialized_value: String = byte_serialize(value.as_bytes()).collect(); +pub fn encode(value: &str) -> String { + let serialized_value: String = utf8_percent_encode(value, NON_ALPHANUMERIC).to_string(); // Encode space to '%20' as per url standard // Should be fixed by https://github.com/servo/rust-url/pull/1028 serialized_value.replace("+", "%20") @@ -30,12 +30,12 @@ pub fn encoded(value: String) -> String { #[cfg(test)] mod tests { - use super::encoded; + use super::encode; #[test] fn test_encode_value() { let id = "Wired #1"; - let encoded_id = encoded(id.to_string()); + let encoded_id = encode(id); assert_eq!(encoded_id, "Wired%20%231"); } } From d4673823a44a106cd108846f71b6bf0f0cf0ce3c Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 24 Jul 2025 13:42:38 +0100 Subject: [PATCH 4/4] Remove leftover conversion --- rust/agama-lib/src/utils/url.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rust/agama-lib/src/utils/url.rs b/rust/agama-lib/src/utils/url.rs index ac1766a786..9d3c8dda4c 100644 --- a/rust/agama-lib/src/utils/url.rs +++ b/rust/agama-lib/src/utils/url.rs @@ -21,10 +21,7 @@ use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; pub fn encode(value: &str) -> String { - let serialized_value: String = utf8_percent_encode(value, NON_ALPHANUMERIC).to_string(); - // Encode space to '%20' as per url standard - // Should be fixed by https://github.com/servo/rust-url/pull/1028 - serialized_value.replace("+", "%20") + utf8_percent_encode(value, NON_ALPHANUMERIC).to_string() } #[cfg(test)]