Dates: four-digit years from 1900 to 2100
CI / secret scan (push) Successful in 4s
CI / fmt, clippy, tests (push) Successful in 20s

Chromium's date input lets the year part take six digits when the input
has no max, so typing 2026 and then 11 for the month gave 202611-12-05
(reported on the live app). Every date input now carries
min="1900-01-01" and max="2100-12-31", so the year part stops at four
digits and moves on to the month. Checked in Edge: typing 20261112 gives
2026-11-12, where it left the field empty before.

The server checks the same years for every date field
(dates::parse_form_date). Person, passport and address dates were only
parsed, so a two-digit year such as 0026-11-12 would have been saved;
stay records had the range already. A six-digit year never parsed, so no
such date can be in the database.

Tests: the parser's cases; the person, passport and arrival forms refuse
both years and save nothing; every date input on every page carries the
limits (pages.rs).
This commit is contained in:
grabowski committed 2026-11-17 21:15:14 +07:00
1 parent 38070ee135
commit d543c929e9
6 files changed
+147 -10

No files matched your search

+71
View File
@@ -164,6 +164,77 @@ async fn validation_and_edits_with_changed_fields(pool: PgPool) {
assert_eq!(audit_rows(&pool, id).await.last().unwrap().0, "view");
}
/// Chromium sends `202611-12-05` when the year part took six digits, and
/// `0026-...` for a two-digit year; neither may reach the database.
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
async fn dates_need_a_four_digit_year_from_1900_to_2100(pool: PgPool) {
let app = local(pool.clone());
let r = app
.post(
"/people",
&[
("surname", "Doe"),
("first_name", "Jane"),
("date_of_birth", "0026-11-12"),
],
)
.await;
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
assert!(
r.text().contains("Enter a year from 1900 to 2100."),
"{}",
r.text()
);
let r = app
.post("/people", &[("surname", "Doe"), ("first_name", "Jane")])
.await;
let id = id_from(r.location());
let r = app
.post(
&format!("/people/{id}/passports"),
&[
("number", "X1234567"),
("issuing_country", "USA"),
("issued_on", "202611-12-05"),
("expires_on", "2036-11-11"),
],
)
.await;
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
let t = r.text();
assert!(t.contains("Enter a date such as 2026-11-17."), "{t}");
assert!(
r.body.contains("value=\"202611-12-05\""),
"the typed value stays"
);
let r = app
.post(
&format!("/people/{id}/arrivals"),
&[
("arrived_on", "0026-09-01"),
("admission", "exempt"),
("permitted_until", "2026-10-30"),
],
)
.await;
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
assert!(
r.text().contains("Enter a year from 1900 to 2100."),
"{}",
r.text()
);
let saved: i64 = sqlx::query_scalar(
"SELECT (SELECT count(*) FROM passports) + (SELECT count(*) FROM arrivals)",
)
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(saved, 0);
}
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
async fn archive_and_restore(pool: PgPool) {
let app = local(pool.clone());