Skip to content

Commit 133c776

Browse files
committed
Changes based on CR
1 parent c60a15e commit 133c776

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

rust/agama-lib/src/network/client.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use super::{settings::NetworkConnection, types::Device};
2222
use crate::http::{BaseHTTPClient, BaseHTTPClientError};
23-
use url::form_urlencoded::byte_serialize;
23+
use crate::utils::url::encoded;
2424

2525
#[derive(Debug, thiserror::Error)]
2626
pub enum NetworkClientError {
@@ -57,8 +57,7 @@ impl NetworkClient {
5757

5858
/// Returns an array of network connections
5959
pub async fn connection(&self, id: &str) -> Result<NetworkConnection, NetworkClientError> {
60-
let encoded_id: String = byte_serialize(id.as_bytes()).collect();
61-
let encoded_id = encoded_id.replace("+", "%20");
60+
let encoded_id = encoded(id.to_string());
6261
let json = self
6362
.client
6463
.get::<NetworkConnection>(format!("/network/connections/{encoded_id}").as_str())
@@ -73,8 +72,7 @@ impl NetworkClient {
7372
connection: NetworkConnection,
7473
) -> Result<(), NetworkClientError> {
7574
let id = connection.id.clone();
76-
let encoded_id: String = byte_serialize(id.as_bytes()).collect();
77-
let encoded_id = encoded_id.replace("+", "%20");
75+
let encoded_id = encoded(id.to_string());
7876
let response = self.connection(id.as_str()).await;
7977

8078
if response.is_ok() {

rust/agama-lib/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
2323
mod file_format;
2424
mod transfer;
25+
pub mod url;
2526

2627
pub use file_format::*;
2728
pub use transfer::*;

rust/agama-lib/src/utils/url.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) [2025] SUSE LLC
2+
//
3+
// All Rights Reserved.
4+
//
5+
// This program is free software; you can redistribute it and/or modify it
6+
// under the terms of the GNU General Public License as published by the Free
7+
// Software Foundation; either version 2 of the License, or (at your option)
8+
// any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful, but WITHOUT
11+
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13+
// more details.
14+
//
15+
// You should have received a copy of the GNU General Public License along
16+
// with this program; if not, contact SUSE LLC.
17+
//
18+
// To contact SUSE LLC about this file by physical or electronic mail, you may
19+
// find current contact information at www.suse.com.
20+
21+
use url::form_urlencoded::byte_serialize;
22+
23+
pub fn encoded(value: String) -> String {
24+
let serialized_value: String = byte_serialize(value.as_bytes()).collect();
25+
// Encode space to '%20' as per url standard
26+
// Should be fixed by https://github.com/servo/rust-url/pull/1028
27+
serialized_value.replace("+", "%20")
28+
}
29+
30+
#[cfg(test)]
31+
mod tests {
32+
33+
use super::encoded;
34+
35+
#[test]
36+
fn test_encode_value() {
37+
let id = "Wired #1";
38+
let encoded_id = encoded(id.to_string());
39+
assert_eq!(encoded_id, "Wired%20%231");
40+
}
41+
}

0 commit comments

Comments
 (0)