Merge pull request #11876 from jackwilsdon/osc8

Filter OSC 8 correctly
This commit is contained in:
Eelco Dolstra 2024-11-13 18:27:27 +01:00 committed by GitHub
commit 2d2b9cd45d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -57,4 +57,9 @@ TEST(filterANSIEscapes, utf8)
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");
}
} // namespace nix

View File

@ -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++;
}