diff --git a/src/libutil/terminal.cc b/src/libutil/terminal.cc index 5d5ff7dcb..db7a6fcd1 100644 --- a/src/libutil/terminal.cc +++ b/src/libutil/terminal.cc @@ -45,6 +45,13 @@ std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int w while (i != s.end() && *i >= 0x20 && *i <= 0x2f) e += *i++; // eat final byte if (i != s.end() && *i >= 0x40 && *i <= 0x7e) e += last = *i++; + } else if (i != s.end() && *i == ']') { + // OSC + e += *i++; + // eat ESC + while (i != s.end() && *i != '\e') e += *i++; + // eat backslash + if (i != s.end() && *i == '\\') e += last = *i++; } else { if (i != s.end() && *i >= 0x40 && *i <= 0x5f) e += *i++; } diff --git a/tests/unit/libutil/tests.cc b/tests/unit/libutil/tests.cc index 2b73d323b..5e3415edf 100644 --- a/tests/unit/libutil/tests.cc +++ b/tests/unit/libutil/tests.cc @@ -700,4 +700,9 @@ namespace nix { ASSERT_EQ(filterANSIEscapes("f๐ˆ๐ˆbรคr", true, 4), "f๐ˆ๐ˆb"); } + TEST(filterANSIEscapes, osc8) + { + ASSERT_EQ(filterANSIEscapes("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\"), "This is a link"); + } + }