Links to ts3server://, teamspeak:// and tmspk.gg in chat were only copied. voelin_model::Link reads them, and invite_link now writes through ServerLink::to_url, so a copied invite reads back the same (a '/' in a channel's name stays %2F in the link, \/ in the path). App::open_link (links.rs) finds the saved server with that address (vm::servers::same_address; of several, the one in voice, else the one shown: link_server). In voice on it, it moves into the link's channel (channel_by_path) through join_channel, so a locked channel asks for its password when the link's is missing or wrong. Otherwise the server dialog opens filled in by link_form, over the saved server's form when there is one: its nickname stays. Nothing connects before Connect. Invite codes need a TeamSpeak service; a toast says so. VOELIN_OPEN=link:<url> goes through inbox::Request::OpenLink, where the platform's links will come in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
//! Percent escapes in links: file links ([`crate::FileRef`]) and server
|
|
//! links ([`crate::Link`]).
|
|
|
|
/// `%XX` escapes to bytes, read as UTF-8 (a `+` stays: file names and
|
|
/// passwords keep theirs).
|
|
pub(crate) fn decode(s: &str) -> String {
|
|
let bytes = s.as_bytes();
|
|
let hex = |b: u8| (b as char).to_digit(16);
|
|
let mut out = Vec::with_capacity(bytes.len());
|
|
let mut i = 0;
|
|
while i < bytes.len() {
|
|
if bytes[i] == b'%'
|
|
&& let (Some(h), Some(l)) =
|
|
(bytes.get(i + 1).and_then(|b| hex(*b)), bytes.get(i + 2).and_then(|b| hex(*b)))
|
|
{
|
|
out.push((h * 16 + l) as u8);
|
|
i += 3;
|
|
continue;
|
|
}
|
|
out.push(bytes[i]);
|
|
i += 1;
|
|
}
|
|
String::from_utf8_lossy(&out).into_owned()
|
|
}
|
|
|
|
/// Every byte but letters, digits and `-._~` as `%XX`.
|
|
pub(crate) fn encode(s: &str) -> String {
|
|
let mut out = String::with_capacity(s.len());
|
|
for b in s.bytes() {
|
|
if b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_' | b'.' | b'~') {
|
|
out.push(b as char);
|
|
} else {
|
|
out.push_str(&format!("%{b:02X}"));
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn escapes() {
|
|
assert_eq!(decode("Raid%20Night"), "Raid Night");
|
|
assert_eq!(decode("%C3%84b"), "Äb");
|
|
assert_eq!(decode("a+b"), "a+b");
|
|
// A broken escape stays as it is.
|
|
assert_eq!(decode("100%"), "100%");
|
|
assert_eq!(decode("%zz"), "%zz");
|
|
assert_eq!(encode("Chill & Co/Ä"), "Chill%20%26%20Co%2F%C3%84");
|
|
assert_eq!(decode(&encode("a b+c%")), "a b+c%");
|
|
}
|
|
}
|