Conversation
We don't want users to name their proceses `all` or whatever as it'll break things, so let's prohibit it. I've currently prohibited empty strings, `all` and `annual` (could cause issues if a user names a season this). Closes #548.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a bug fix that disallows invalid ID values by prohibiting empty strings and the forbidden keywords "all" and "annual".
- Replaces the derived implementation of Deserialize with a custom one that enforces the ID restrictions.
- Adds trimming and forbidden value checks during deserialization.
Comments suppressed due to low confidence (1)
src/id.rs:54
- The current implementation reassigns 'id' by trimming the string, resulting in a &str that borrows from a temporary String, which could lead to lifetime issues. Consider capturing the trimmed value as an owned String, e.g., 'let id = id.trim().to_owned();', to ensure it remains valid.
let id = id.trim();
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #572 +/- ##
==========================================
+ Coverage 89.64% 89.67% +0.03%
==========================================
Files 37 37
Lines 3381 3401 +20
Branches 3381 3401 +20
==========================================
+ Hits 3031 3050 +19
Misses 173 173
- Partials 177 178 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dalonsoa
left a comment
There was a problem hiding this comment.
I've a question/suggestion to improve readability, but this looks good, otherwise.
| for forbidden in FORBIDDEN_IDS.iter() { | ||
| if id.eq_ignore_ascii_case(forbidden) { | ||
| return Err(D::Error::custom(format!( | ||
| "'{id}' is an invalid value for an ID" | ||
| ))); | ||
| } | ||
| } |
There was a problem hiding this comment.
Is there any reason for not using something like:
| for forbidden in FORBIDDEN_IDS.iter() { | |
| if id.eq_ignore_ascii_case(forbidden) { | |
| return Err(D::Error::custom(format!( | |
| "'{id}' is an invalid value for an ID" | |
| ))); | |
| } | |
| } | |
| if ["all", "annual"].contains(&id) { | |
| return Err(D::Error::custom(format!( | |
| "'{id}' is an invalid value for an ID" | |
| ))); | |
| } |
There seems to be more succinct and readable ways of making this check: https://stackoverflow.com/a/72381091/3778792
There was a problem hiding this comment.
It currently ignores case. You could convert id to lowercase then do the check, which would mean an extra allocation, though that's probably not the end of the world.
There was a problem hiding this comment.
We could rewrite this with iterators, i.e. if FORBIDDEN_IDS.iter().any(..., but I'm not sure that would be much cleaner.
tsmbland
left a comment
There was a problem hiding this comment.
Good idea
Buuut... maybe add some tests :)
| for forbidden in FORBIDDEN_IDS.iter() { | ||
| if id.eq_ignore_ascii_case(forbidden) { | ||
| return Err(D::Error::custom(format!( | ||
| "'{id}' is an invalid value for an ID" | ||
| ))); | ||
| } | ||
| } |
Description
We don't want users to name their proceses
allor whatever as it'll break things, so let's prohibit it. I've currently prohibited empty strings,allandannual(could cause issues if a user names a season this).Closes #548.
Type of change
Key checklist
$ cargo test$ cargo docFurther checks