mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Checking if emoji byte doesn't get out of bounds
This commit is contained in:
parent
59040c53e4
commit
89afa8e149
@ -108,7 +108,8 @@ auto Language::update() -> void {
|
||||
fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description),
|
||||
fmt::arg("long", layout_.full_name),
|
||||
fmt::arg("variant", layout_.variant)));
|
||||
fmt::arg("variant", layout_.variant),
|
||||
fmt::arg("flag", layout_.country_flag())));
|
||||
label_.set_tooltip_markup(tooltip_display_layout);
|
||||
} else {
|
||||
label_.set_tooltip_markup(display_layout);
|
||||
@ -215,9 +216,13 @@ Language::XKBContext::~XKBContext() {
|
||||
}
|
||||
|
||||
std::string Language::Layout::country_flag() const {
|
||||
static std::string result = "\xf0\x9f\x87\xff\xf0\x9f\x87\xff";
|
||||
result[3] = short_name[0] - 0xbb;
|
||||
result[7] = short_name[1] - 0xbb;
|
||||
return result;
|
||||
if (short_name.size() != 2) return "";
|
||||
unsigned char result[] = "\xf0\x9f\x87\x00\xf0\x9f\x87\x00";
|
||||
result[3] = short_name[0] + 0x45;
|
||||
result[7] = short_name[1] + 0x45;
|
||||
// Check if both emojis are in A-Z symbol bounds
|
||||
if (result[3] < 0xa6 || result[3] > 0xbf) return "";
|
||||
if (result[7] < 0xa6 || result[7] > 0xbf) return "";
|
||||
return std::string{reinterpret_cast<char*>(result)};
|
||||
}
|
||||
} // namespace waybar::modules::sway
|
||||
|
Loading…
Reference in New Issue
Block a user