WeekHours validation (src/backend/data.rs) accepts strings that DayHours::try_new then rejects. The form passes client-side validation, update_hours fails on DayHours::try_new(hours.hours())? and the user sees a generic server error instead of a validation message.
Verified inputs — all pass WeekHours::validate() and all fail DayHours::try_new():
08:00 - 12:00, nonsense
08:00 - 12:00 garbage
08:00 - 12:00, (trailing comma)
Cause
RE_HOURS is ^$|(^\d{2}:\d{2} ?- ?\d{2}:\d{2} ?(\(\d+\))?,? ?)+ — it has no $ at the end, so anything after the first valid interval is accepted. The ^ inside the repeated group also means the group can only match once.
validate_hours returns Ok(()) when DayHours::try_new fails, so the parse error is silently ignored there too.
Suggested fix
Anchor the regex at the end and move ^ out of the repeated group, or drop the regex and validate by calling DayHours::try_new directly.
Make validate_hours return a validation error when parsing fails.
Add unit tests for the inputs above to week_hours_rejects_wrong_format.
Found while writing unit tests (#2).
## Problem
`WeekHours` validation (`src/backend/data.rs`) accepts strings that `DayHours::try_new` then rejects. The form passes client-side validation, `update_hours` fails on `DayHours::try_new(hours.hours())?` and the user sees a generic server error instead of a validation message.
Verified inputs — all pass `WeekHours::validate()` and all fail `DayHours::try_new()`:
- `08:00 - 12:00, nonsense`
- `08:00 - 12:00 garbage`
- `08:00 - 12:00,` (trailing comma)
## Cause
- `RE_HOURS` is `^$|(^\d{2}:\d{2} ?- ?\d{2}:\d{2} ?(\(\d+\))?,? ?)+` — it has no `$` at the end, so anything after the first valid interval is accepted. The `^` inside the repeated group also means the group can only match once.
- `validate_hours` returns `Ok(())` when `DayHours::try_new` fails, so the parse error is silently ignored there too.
## Suggested fix
- Anchor the regex at the end and move `^` out of the repeated group, or drop the regex and validate by calling `DayHours::try_new` directly.
- Make `validate_hours` return a validation error when parsing fails.
- Add unit tests for the inputs above to `week_hours_rejects_wrong_format`.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Found while writing unit tests (#2).
Problem
WeekHoursvalidation (src/backend/data.rs) accepts strings thatDayHours::try_newthen rejects. The form passes client-side validation,update_hoursfails onDayHours::try_new(hours.hours())?and the user sees a generic server error instead of a validation message.Verified inputs — all pass
WeekHours::validate()and all failDayHours::try_new():08:00 - 12:00, nonsense08:00 - 12:00 garbage08:00 - 12:00,(trailing comma)Cause
RE_HOURSis^$|(^\d{2}:\d{2} ?- ?\d{2}:\d{2} ?(\(\d+\))?,? ?)+— it has no$at the end, so anything after the first valid interval is accepted. The^inside the repeated group also means the group can only match once.validate_hoursreturnsOk(())whenDayHours::try_newfails, so the parse error is silently ignored there too.Suggested fix
^out of the repeated group, or drop the regex and validate by callingDayHours::try_newdirectly.validate_hoursreturn a validation error when parsing fails.week_hours_rejects_wrong_format.