aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Linford <tlinford@users.noreply.github.com>2022-04-28 11:45:21 +0200
committerGitHub <noreply@github.com>2022-04-28 11:45:21 +0200
commit188febfc0591e99d1577d3032076eac9ca9a7e33 (patch)
tree2d92b14a811bd81db644d069420a1c1b553aa9cb
parentdocs(changelog): ipc fix (diff)
downloadsl0ppij-188febfc0591e99d1577d3032076eac9ca9a7e33.tar.gz
sl0ppij-188febfc0591e99d1577d3032076eac9ca9a7e33.tar.xz
sl0ppij-188febfc0591e99d1577d3032076eac9ca9a7e33.zip
fix(stability): avoid link handler panic on bad index (#1356)
root cause needs investigating, but for now fix the crash.
-rw-r--r--zellij-server/src/panes/link_handler.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/zellij-server/src/panes/link_handler.rs b/zellij-server/src/panes/link_handler.rs
index 3de81c3a..e6119a6c 100644
--- a/zellij-server/src/panes/link_handler.rs
+++ b/zellij-server/src/panes/link_handler.rs
@@ -50,17 +50,31 @@ impl LinkHandler {
}
pub fn output_osc8(&self, link_anchor: Option<LinkAnchor>) -> Option<String> {
- link_anchor.map(|link| match link {
- LinkAnchor::Start(index) => {
- let link = self.links.get(&index).unwrap();
- let id = link
- .id
- .as_ref()
- .map_or("".to_string(), |id| format!("id={}", id));
- format!("\u{1b}]8;{};{}{}", id, link.uri, TERMINATOR)
- }
- LinkAnchor::End => format!("\u{1b}]8;;{}", TERMINATOR),
- })
+ link_anchor
+ .map(|link| match link {
+ LinkAnchor::Start(index) => {
+ let link = self.links.get(&index);
+
+ let output = link.map(|link| {
+ let id = link
+ .id
+ .as_ref()
+ .map_or("".to_string(), |id| format!("id={}", id));
+ format!("\u{1b}]8;{};{}{}", id, link.uri, TERMINATOR)
+ });
+
+ if output.is_none() {
+ log::warn!(
+ "attempted to output osc8 link start, but id: {} was not found!",
+ index
+ );
+ }
+
+ output
+ }
+ LinkAnchor::End => Some(format!("\u{1b}]8;;{}", TERMINATOR)),
+ })
+ .flatten()
}
}
@@ -108,4 +122,11 @@ mod tests {
let expected = format!("\u{1b}]8;;{}", TERMINATOR);
assert_eq!(link_handler.output_osc8(anchor).unwrap(), expected);
}
+
+ #[test]
+ fn return_none_on_missing_link_id() {
+ let link_handler = LinkHandler::default();
+ let anchor = LinkAnchor::Start(100);
+ assert_eq!(link_handler.output_osc8(Some(anchor)), None);
+ }
}