fix: Modules did not validate tags used in formats

The 'value' variable that was used for validation, was empty because it
was used in a move at the beginning of the function.

Fixes #3043
This commit is contained in:
patrick96 2023-11-16 22:19:41 +01:00 committed by Patrick Ziegler
parent 432e19df01
commit c552df3b66
2 changed files with 7 additions and 10 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `internal/tray`: The module must use the `<tray>` tag (this is the default) ([`#3037`](https://github.com/polybar/polybar/pull/3037)) - `internal/tray`: The module must use the `<tray>` tag (this is the default) ([`#3037`](https://github.com/polybar/polybar/pull/3037))
## Fixed ## Fixed
- Modules did not validate that all tags (e.g. `<label>`) used in a format were valid for that format ([`#3043`](https://github.com/polybar/polybar/issues/3043), [`#3045`](https://github.com/polybar/polybar/pull/3045))
- `internal/tray`: Fixed `module-margin` and `separator` being applied to completely empty tray module ([`#3036`](https://github.com/polybar/polybar/issues/3036), [`#3037`](https://github.com/polybar/polybar/pull/3037)) - `internal/tray`: Fixed `module-margin` and `separator` being applied to completely empty tray module ([`#3036`](https://github.com/polybar/polybar/issues/3036), [`#3037`](https://github.com/polybar/polybar/pull/3037))
## [3.7.0] - 2023-11-05 ## [3.7.0] - 2023-11-05

View File

@ -92,7 +92,7 @@ namespace modules {
}; };
auto format = make_unique<module_format>(); auto format = make_unique<module_format>();
format->value = move(value); format->value = std::move(value);
format->fg = m_conf.get(m_modname, name + "-foreground", formatdef("foreground", format->fg)); format->fg = m_conf.get(m_modname, name + "-foreground", formatdef("foreground", format->fg));
format->bg = m_conf.get(m_modname, name + "-background", formatdef("background", format->bg)); format->bg = m_conf.get(m_modname, name + "-background", formatdef("background", format->bg));
format->ul = m_conf.get(m_modname, name + "-underline", formatdef("underline", format->ul)); format->ul = m_conf.get(m_modname, name + "-underline", formatdef("underline", format->ul));
@ -122,18 +122,14 @@ namespace modules {
tag_collection.insert(tag_collection.end(), tags.begin(), tags.end()); tag_collection.insert(tag_collection.end(), tags.begin(), tags.end());
tag_collection.insert(tag_collection.end(), whitelist.begin(), whitelist.end()); tag_collection.insert(tag_collection.end(), whitelist.begin(), whitelist.end());
size_t start, end; size_t start = 0;
while ((start = value.find('<')) != string::npos && (end = value.find('>', start)) != string::npos) { size_t end = 0;
if (start > 0) { while ((start = format->value.find('<', start)) != string::npos && (end = format->value.find('>', start)) != string::npos) {
value.erase(0, start); string tag{format->value.substr(start, end - start + 1)};
end -= start;
start = 0;
}
string tag{value.substr(start, end + 1)};
if (find(tag_collection.begin(), tag_collection.end(), tag) == tag_collection.end()) { if (find(tag_collection.begin(), tag_collection.end(), tag) == tag_collection.end()) {
throw undefined_format_tag(tag + " is not a valid format tag for \"" + name + "\""); throw undefined_format_tag(tag + " is not a valid format tag for \"" + name + "\"");
} }
value.erase(0, tag.size()); start = end + 1;
} }
m_formats.insert(make_pair(move(name), move(format))); m_formats.insert(make_pair(move(name), move(format)));