Skip to content

Commit ee8082d

Browse files
fix: remove nonalphanumeric characters from interface name (#227)
1 parent 1172d2e commit ee8082d

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src-tauri/src/utils.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
appstate::AppState,
1616
commands::{LocationInterfaceDetails, Payload},
1717
database::{
18-
models::location::peer_to_location_stats, models::tunnel::peer_to_tunnel_stats,
18+
models::{location::peer_to_location_stats, tunnel::peer_to_tunnel_stats},
1919
ActiveConnection, Connection, DbPool, Location, Tunnel, TunnelConnection, WireguardKeys,
2020
},
2121
error::Error,
@@ -119,12 +119,6 @@ pub async fn setup_interface(
119119
}
120120
}
121121

122-
/// Helper function to remove whitespace from location name
123-
#[must_use]
124-
pub fn remove_whitespace(s: &str) -> String {
125-
s.chars().filter(|c| !c.is_whitespace()).collect()
126-
}
127-
128122
fn find_random_free_port() -> Option<u16> {
129123
const MAX_PORT: u16 = 65535;
130124
const MIN_PORT: u16 = 6000;
@@ -162,11 +156,11 @@ pub fn get_interface_name() -> String {
162156
"utun0".into()
163157
}
164158

159+
/// Strips location name of all non-alphanumeric characters returning usable interface name.
165160
#[cfg(not(target_os = "macos"))]
166-
/// Returns interface name for location
167161
#[must_use]
168162
pub fn get_interface_name(name: &str) -> String {
169-
remove_whitespace(name)
163+
name.chars().filter(|c| c.is_alphanumeric()).collect()
170164
}
171165

172166
fn is_port_free(port: u16) -> bool {

0 commit comments

Comments
 (0)