From cab25161054c50fd6c705db4ceefef0f1e5a9575 Mon Sep 17 00:00:00 2001 From: Suliman Abdulrazzaq <144490671+SulimanAbdulrazzaq@users.noreply.github.com> Date: Tue, 29 Sep 2026 05:33:49 +0300 Subject: [PATCH] wezterm-escape-parser: keep `;` in OSC 8 hyperlink URIs (#8207) The OSC parser splits the whole sequence on `;`, so a hyperlink whose URI contains a `;` (for example `data:text/plain;base64,...` or a URL with `;` in its path or query) arrived with more than three parameters and was rejected. The link was then dropped and the OSC was tracked as Unspecified. `;` is a valid URI character, so treat everything after the params as the URI. --- wezterm-escape-parser/src/hyperlink.rs | 9 ++++++--- wezterm-escape-parser/src/osc.rs | 21 +++++++++++++++++++++ wezterm-escape-parser/src/parser/mod.rs | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/wezterm-escape-parser/src/hyperlink.rs b/wezterm-escape-parser/src/hyperlink.rs index 510377a2a..a966416c7 100644 --- a/wezterm-escape-parser/src/hyperlink.rs +++ b/wezterm-escape-parser/src/hyperlink.rs @@ -74,13 +74,16 @@ impl Hyperlink { } pub fn parse(osc: &[&[u8]]) -> Result> { - ensure!(osc.len() == 3, "wrong param count"); - if osc[1].is_empty() && osc[2].is_empty() { + ensure!(osc.len() >= 3, "wrong param count"); + // Take everything after the params, so any further `;…` are counted as part of the URI + // e.g. `https://example.com/a;b;c=d` would have been split in 3 parts by the OSC splitter. + let uri = osc[2..].join(&b';'); + if osc[1].is_empty() && uri.is_empty() { // Clearing current hyperlink Ok(None) } else { let param_str = String::from_utf8(osc[1].to_vec())?; - let uri = String::from_utf8(osc[2].to_vec())?; + let uri = String::from_utf8(uri)?; let mut params = HashMap::new(); if !param_str.is_empty() { diff --git a/wezterm-escape-parser/src/osc.rs b/wezterm-escape-parser/src/osc.rs index 57363a254..67368cfb2 100644 --- a/wezterm-escape-parser/src/osc.rs +++ b/wezterm-escape-parser/src/osc.rs @@ -1486,6 +1486,27 @@ mod test { Hyperlink::parse(&[b"8", b"", b"x"]).unwrap(), Some(Hyperlink::new("x")) ); + + // `;` is valid in a URI, so everything after the params is the URI + assert_eq!( + parse( + &["8", "", "https://example.com/a", "b", "c=d"], + "\x1b]8;;https://example.com/a;b;c=d\x1b\\" + ), + OperatingSystemCommand::SetHyperlink(Some(Hyperlink::new( + "https://example.com/a;b;c=d" + ))) + ); + assert_eq!( + parse( + &["8", "id=foo", "data:text/plain", "base64,aGk="], + "\x1b]8;id=foo;data:text/plain;base64,aGk=\x1b\\" + ), + OperatingSystemCommand::SetHyperlink(Some(Hyperlink::new_with_id( + "data:text/plain;base64,aGk=", + "foo" + ))) + ); } #[test] diff --git a/wezterm-escape-parser/src/parser/mod.rs b/wezterm-escape-parser/src/parser/mod.rs index 44ed26a63..b3d6e4222 100644 --- a/wezterm-escape-parser/src/parser/mod.rs +++ b/wezterm-escape-parser/src/parser/mod.rs @@ -674,6 +674,23 @@ mod test { assert_eq!(encode(&actions), "\x1b]532534523;hello\x1b\\"); } + #[test] + fn hyperlink_uri_with_semicolons() { + let mut p = Parser::new(); + let actions = p.parse_as_vec(b"\x1b]8;id=x;https://example.com/a;b?c=d;e\x07"); + let link = crate::hyperlink::Hyperlink::new_with_id("https://example.com/a;b?c=d;e", "x"); + assert_eq!( + vec![Action::OperatingSystemCommand(Box::new( + OperatingSystemCommand::SetHyperlink(Some(link)), + ))], + actions + ); + assert_eq!( + encode(&actions), + "\x1b]8;id=x;https://example.com/a;b?c=d;e\x1b\\" + ); + } + #[test] fn test_emoji_title_osc() { let input = "\x1b]0;\u{1f915}\x07";