fix: Replace str::len() with as_bytes().len()#1900
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces str::len() with str::as_bytes().len() to comply with a project-specific clippy lint. While the change in crates/tests-integration/src/container.rs is correct for a hex string, the change in crates/lib/src/status.rs introduces a latent bug. It calculates the maximum label length in bytes, but the corresponding write_row_name function calculates padding based on character count. This will cause misaligned text if labels contain multi-byte Unicode characters. My review includes a suggestion to use chars().count(), which correctly measures character count for alignment purposes and should also satisfy the clippy lint.
7f237bc to
e0d64cd
Compare
- status.rs: Use UnicodeWidthStr::width() for correct display alignment - container.rs: Use as_bytes().len() for hex string length verification - Add unicode-width dependency (already a transitive dep via comfy-table) Assisted-by: Cursor (Auto) Signed-off-by: Shion Tanaka <shtanaka@redhat.com>
Head branch was pushed to by a user without write access
e0d64cd to
9cfa2ca
Compare
|
And I guess a side thing to investigate here is why our CI is not properly gating on this, probably something missing in |
Fix clippy::disallowed_methods warnings that appear in clean builds but may be hidden by CI cache.
Changes
crates/lib/src/status.rs: Replacelabel.len()withlabel.as_bytes().len()crates/tests-integration/src/container.rs: Replacedigest.len()withdigest.as_bytes().len()Background
The project's
clippy.tomldisallowsstr::len()to make the intent of getting byte length explicit.