Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate display names with longer than 30 chars #171

Merged
merged 4 commits into from
Jun 20, 2024

Conversation

micbakos-rdx
Copy link
Contributor

  • User reported with profile that had display names with longer than 30 chars. This was resulting the deserialisation of the profile to return an error.
  • The display names are now truncated.
  • Question for @CyonAlexRDX: The CommonError::InvalidDisplayNameTooLong in now unused. I purposely did not delete it. Is it safe to remove it and fix the error codes of the rest of the following errors?
  • Question to all. I used the truncate() function. This might panic if "new_len does not lie on a char boundary." Can someone help with suggestions on how this might fail? Or even suggest a better function?

found: value.len() as u64,
});
}
value.truncate(Self::MAX_LEN);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the same you used in recent PR? .chars().take(Self::MAX_LEN).collect() instead? which seemed safe.?

Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ok to leave error variant for now. Too costly to shift all codes... you might rename it UnusedError or something? And make a note that we can use "that slot" if we want

@micbakos-rdx
Copy link
Contributor Author

Yes ok to leave error variant for now. Too costly to shift all codes... you might rename it UnusedError or something? And make a note that we can use "that slot" if we want

Clever idea, will do that

@@ -230,6 +230,7 @@ pub enum CommonError {
#[error("Invalid DisplayName cannot be empty.")]
InvalidDisplayNameEmpty = 10062,

/// WARNING: UNUSED, can be replaced by any new error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No warning needed imo. Just rename the variant to FREE and the error message


Ok(Self { value })
Ok(Self {
value: value.chars().take(Self::MAX_LEN).collect(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do this in two places, might as well write a func or method for it, put it in string_utils and add tests for it.

You can perhaps extend the trait StrExt

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 98.8%. Comparing base (8b5c747) to head (15eeb61).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #171     +/-   ##
=======================================
- Coverage   98.8%   98.8%   -0.1%     
=======================================
  Files        756     756             
  Lines      11348   11347      -1     
  Branches      27      27             
=======================================
- Hits       11213   11212      -1     
  Misses       133     133             
  Partials       2       2             
Flag Coverage Δ
kotlin 99.7% <ø> (ø)
rust 98.5% <66.6%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/core/error/common_error.rs 100.0% <ø> (ø)
src/core/utils/string_utils.rs 100.0% <100.0%> (ø)
src/profile/v100/entity/display_name.rs 100.0% <100.0%> (ø)
src/core/error/common_error_map.rs 63.6% <0.0%> (ø)

Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@micbakos-rdx micbakos-rdx merged commit 31dd1ab into main Jun 20, 2024
8 checks passed
@micbakos-rdx micbakos-rdx deleted the fix/truncate-long-display-names branch June 20, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust 🦀 Changes in Rust Sargon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants