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.
This commit is contained in:
1 parent
b09b56c29c
commit
cab2516105
3 files changed
+44
-3
No files matched your search
@@ -74,13 +74,16 @@ impl Hyperlink {
|
||||
}
|
||||
|
||||
pub fn parse(osc: &[&[u8]]) -> Result<Option<Hyperlink>> {
|
||||
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() {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user