(t *testing.T)
| 461 | } |
| 462 | |
| 463 | func TestOSC8ControlsAreStrippedFromOutput(t *testing.T) { |
| 464 | tty := &spyTty{MockTerm: vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})} |
| 465 | s, err := NewTerminfoScreenFromTty(tty, OptAltScreen(false)) |
| 466 | if err != nil { |
| 467 | t.Fatalf("failed to get screen: %v", err) |
| 468 | } |
| 469 | if err := s.Init(); err != nil { |
| 470 | t.Fatalf("failed to initialize screen: %v", err) |
| 471 | } |
| 472 | defer s.Fini() |
| 473 | |
| 474 | style := StyleDefault. |
| 475 | Url("http://exa\x07mple.com/\x1b\\path"). |
| 476 | UrlId("id\x00\x1f\x7f\x80\x9fend") |
| 477 | |
| 478 | s.PutStrStyled(0, 0, "X", style) |
| 479 | s.Show() |
| 480 | |
| 481 | out := tty.Output() |
| 482 | const prefix = "\x1b]8;id=idend;" |
| 483 | _, link, ok := strings.Cut(out, prefix) |
| 484 | if !ok { |
| 485 | t.Fatalf("missing OSC 8 link open sequence in output: %q", out) |
| 486 | } |
| 487 | link, _, ok = strings.Cut(link, "\x1b\\") |
| 488 | if !ok { |
| 489 | t.Fatalf("missing OSC 8 terminator in output: %q", out) |
| 490 | } |
| 491 | if link != "http://example.com/\\path" { |
| 492 | t.Fatalf("unexpected emitted URL payload: %q", link) |
| 493 | } |
| 494 | if _, afterLink, ok := strings.Cut(out, "X"); !ok || !strings.Contains(afterLink, "\x1b]8;;\x1b\\") { |
| 495 | t.Fatalf("missing OSC 8 link close sequence after linked content: %q", out) |
| 496 | } |
| 497 | for i := 0; i < len(link); i++ { |
| 498 | c := link[i] |
| 499 | if c <= 0x1f || c == 0x7f || (c >= 0x80 && c <= 0x9f) { |
| 500 | t.Fatalf("control characters survived in emitted URL payload: %q", link) |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | func TestOSC8IdWithoutUrlDoesNotEmitClose(t *testing.T) { |
| 506 | tty := &spyTty{MockTerm: vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})} |
nothing calls this directly
no test coverage detected
searching dependent graphs…