mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Merge pull request #13110 from NixOS/mergify/bp/2.28-maintenance/pr-13109
libutil: amend OSC 8 escape stripping for xterm-style separator (backport #13109)
This commit is contained in:
commit
bf0f35ec69
2 changed files with 21 additions and 4 deletions
|
@ -66,4 +66,12 @@ TEST(filterANSIEscapes, osc8)
|
||||||
ASSERT_EQ(filterANSIEscapes("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\"), "This is a link");
|
ASSERT_EQ(filterANSIEscapes("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\"), "This is a link");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(filterANSIEscapes, osc8_bell_as_sep)
|
||||||
|
{
|
||||||
|
// gcc-14 uses \a as a separator, xterm style:
|
||||||
|
// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
||||||
|
ASSERT_EQ(filterANSIEscapes("\e]8;;http://example.com\aThis is a link\e]8;;\a"), "This is a link");
|
||||||
|
ASSERT_EQ(filterANSIEscapes("\e]8;;http://example.com\a\\This is a link\e]8;;\a"), "\\This is a link");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
@ -95,10 +95,19 @@ std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int w
|
||||||
} else if (i != s.end() && *i == ']') {
|
} else if (i != s.end() && *i == ']') {
|
||||||
// OSC
|
// OSC
|
||||||
e += *i++;
|
e += *i++;
|
||||||
// eat ESC
|
// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda defines
|
||||||
while (i != s.end() && *i != '\e') e += *i++;
|
// two forms of a URI separator:
|
||||||
// eat backslash
|
// 1. ESC '\' (standard)
|
||||||
if (i != s.end() && *i == '\\') e += last = *i++;
|
// 2. BEL ('\a') (xterm-style, used by gcc)
|
||||||
|
|
||||||
|
// eat ESC or BEL
|
||||||
|
while (i != s.end() && *i != '\e' && *i != '\a') e += *i++;
|
||||||
|
if (i != s.end()) {
|
||||||
|
char v = *i;
|
||||||
|
e += *i++;
|
||||||
|
// eat backslash after ESC
|
||||||
|
if (i != s.end() && v == '\e' && *i == '\\') e += last = *i++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (i != s.end() && *i >= 0x40 && *i <= 0x5f) e += *i++;
|
if (i != s.end() && *i >= 0x40 && *i <= 0x5f) e += *i++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue