diff --git a/CHANGELOG.md b/CHANGELOG.md index 010b678f..c4050623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed +- Token min-length calculations would behave differently when non-ASCII characters appear in the token ([`#3074`](https://github.com/polybar/polybar/issues/3074), [`#3087`](https://github.com/polybar/polybar/pull/3087)) by [@nklloyd](https://github.com/nklloyd) - `internal/backlight`: Module could display the literal `%percentage%` token if the backlight reports a value of 0 at startup ([`#3081`](https://github.com/polybar/polybar/pull/3081)) by [@unclechu](https://github.com/unclechu) ## [3.7.1] - 2023-11-27 diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index e5ba8911..4b58deae 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -82,14 +82,15 @@ namespace drawtypes { for (auto&& tok : m_tokens) { string repl{replacement}; + size_t len = string_util::char_len(repl); if (token == tok.token) { - if (tok.max != 0_z && string_util::char_len(repl) > tok.max) { + if (tok.max != 0_z && len > tok.max) { repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix; - } else if (tok.min != 0_z && repl.length() < tok.min) { + } else if (tok.min != 0_z && len < tok.min) { if (tok.rpadding) { - repl.append(tok.min - repl.length(), ' '); + repl.append(tok.min - len, ' '); } else { - repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' '); + repl.insert(0_z, tok.min - len, tok.zpad ? '0' : ' '); } }