From fed4dcd0fd17bdd2bc1b89834dbdc7155633b8a8 Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:34:16 -0800 Subject: [PATCH 1/3] Recognize the OSC 8 hyperlink close in the ANSI style tracker update_with_hyperlink compared the raw sequence (ESC ] 8 ; ; ESC \) with the bare command "8;;", so a close was never recognized and was stored as an open link. Every later chunk was then wrapped in redundant OSC 8 close sequences. Compare the parsed command instead and treat an empty URI as the end of the link. --- src/vscreen.rs | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/vscreen.rs b/src/vscreen.rs index 54678456..61441772 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -125,7 +125,7 @@ impl Attributes { .. } => { if command.starts_with("8;") { - return self.update_with_hyperlink(raw_sequence); + return self.update_with_hyperlink(command, raw_sequence); } /* defer to update_with_unsupported */ } @@ -214,9 +214,9 @@ impl Attributes { false } - fn update_with_hyperlink(&mut self, sequence: &str) -> bool { - if sequence == "8;;" { - // Empty hyperlink ID and HREF -> end of hyperlink. + fn update_with_hyperlink(&mut self, command: &str, sequence: &str) -> bool { + // OSC 8 ; params ; URI -- an empty URI ends the hyperlink (params may be set). + if command.splitn(3, ';').nth(2).is_none_or(str::is_empty) { self.hyperlink.clear(); } else { self.hyperlink.clear(); @@ -1199,4 +1199,33 @@ mod tests { }); assert_eq!(attrs.reverse, ""); } + + #[test] + fn test_osc8_hyperlink_is_tracked_and_closed() { + for (open, close) in [ + ("\x1B]8;;https://example.com/\x1B\\", "\x1B]8;;\x1B\\"), + ("\x1B]8;;https://example.com/\x07", "\x1B]8;;\x07"), + ( + "\x1B]8;id=1;https://example.com/\x1B\\", + "\x1B]8;id=1;\x1B\\", + ), + ] { + let mut style = crate::vscreen::AnsiStyle::new(); + + // Opening a hyperlink must be tracked so it can be re-emitted and closed. + for seq in EscapeSequenceIterator::new(open) { + assert!(style.update(seq)); + } + assert_eq!(style.to_string(), open); + assert_eq!(style.to_reset_sequence(), "\x1B]8;;\x1B\\"); + + // An OSC 8 with an empty URI ends the hyperlink, so nothing is left + // to re-emit before the next chunk or to close after it. + for seq in EscapeSequenceIterator::new(close) { + assert!(style.update(seq)); + } + assert_eq!(style.to_string(), "", "after {close:?}"); + assert_eq!(style.to_reset_sequence(), "", "after {close:?}"); + } + } } From 1fdc48bbd361b3f6e140287c074563136b412443 Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:42:09 -0800 Subject: [PATCH 2/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e0ae7b4..1c197142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ - `--sanitize=always` now also sanitizes piped output. `--sanitize=auto` now sanitizes every file type, but only when the output is a terminal, see #4141 (@curious-rabbit) - Show changes in `--diff` mode and the change-marker column in Git repositories that use the SHA-256 object format (`git init --object-format=sha256`), see #4143 (@BlueX888) - Skip untracked files and files outside a Git repository in `--diff` mode instead of printing an empty frame, see #4148 (@thejesh23) +- Recognize the end of an OSC 8 hyperlink in ANSI input, so later text is no longer wrapped in redundant hyperlink-close sequences, see #4136 (@divya0795) ## Other - Use git version of cross. See #3533 (@OctopusET) From e382987113d99f6c363602ddc58ba18cd2a8ff8a Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Thu, 19 Nov 2026 12:37:18 -0800 Subject: [PATCH 3/3] Re-run CI (codeberg.org submodule fetch failed)