Skip to content

Commit 078a9d7

Browse files
voidstackloopclaude
andcommitted
Add an eleventh check: input type mismatch
Large-scale improvement, back to a new check rather than performance - the last several rounds fixed history I/O; this one follows the same design as check #9/#10 (design -> implement -> mutation-verify -> fmt/clippy -> commit -> push -> confirm CI). check_input_type_mismatch reuses check_autofill_hints' exact mechanism (guess a field's semantic purpose from its label with a regex) but checks the type attribute instead of autocomplete. A field labeled like an email address or phone number left as type="text" (or untyped, which is the same thing) gets no native format validation, and - the real cost that makes this worth a mobile-usability-focused tool - the wrong virtual keyboard on a phone: a full alphabetic layout instead of an email-optimized or numeric-telephone one. Deliberately scoped to only email and phone: both have a well- supported dedicated input type AND an unambiguous label pattern. Something like a ZIP code was deliberately left out - type="number" would actively be the wrong fix there, since it strips a leading zero and adds spinner arrows nobody wants on a ZIP field. A heuristic guess from label wording, same as Autofill hints, so a mismatch is a Warn, not a Fail. New fixture (fixtures/input-type-mismatch-form.html) covers both true positives (email + phone guessed, left as text) and the two negative cases that matter: a field with the identical email-guess label wording but correctly wired as type="email" (no false positive on a form that got it right), and a field matching neither guess. Verified with a mutation test: widened the check's own field selector to also match already-correctly-typed type="email" fields, confirmed the new integration test failed exactly as predicted (the correctly- wired "Confirm email" field got flagged, breaking the false-positive assertion), then restored the fix. cargo fmt/clippy -D warnings clean, full suite green (159 tests). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 13fcd99 commit 078a9d7

5 files changed

Lines changed: 164 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ project doesn't have a release yet, so everything below is grouped under
122122
(that's about a label *existing*, not about a required-looking one
123123
being honored), and not covered by any other check. Always a `Fail`:
124124
the field's own label contradicts its own enforcement.
125+
- An eleventh check, **Input type mismatch**: guesses a field's
126+
semantic purpose from its label the same way Autofill hints does, but
127+
checks the `type` attribute instead of `autocomplete` — a field
128+
labeled like an email address or phone number left as `type="text"`
129+
(or untyped) gets no native format validation, and the wrong virtual
130+
keyboard on mobile (a full alphabetic layout instead of an
131+
email-optimized or numeric-telephone one). Deliberately scoped to
132+
email/phone only: both have a well-supported dedicated `type` and an
133+
unambiguous label pattern, unlike e.g. a ZIP code, where
134+
`type="number"` would actively be the wrong call (it strips a leading
135+
zero and adds spinner arrows). A heuristic guess from label wording,
136+
like Autofill hints, so a mismatch is a `Warn`, not a `Fail`.
125137
- **Optional LLM semantic checks** (`--llm` / `llm:` config): two
126138
provider-agnostic checks — "Error wording (LLM)" and
127139
"Instructions (LLM)" — that score the clarity of validation error

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ your own use.
7979
axe-core checks a *present* `autocomplete` is valid; this catches the
8080
more common gap of a missing one, which matters for anyone leaning on
8181
a password manager or browser autofill (WCAG 1.3.5).
82+
- **Input type mismatch** — flags a field labeled like an email address
83+
or phone number that's left as `type="text"` (or untyped): no native
84+
format validation, and the wrong virtual keyboard on mobile. Scoped to
85+
email/phone only, where the guess is unambiguous and the dedicated
86+
`type` is well-supported — unlike, say, a ZIP code, where
87+
`type="number"` would actively be the wrong call.
8288
- **Input persistence** — fills a field, waits (`--wait`, default 5s), and
8389
checks the value is still there and whether the page started showing
8490
session-timeout wording. A real 15-30 minute timeout isn't waited out by
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head><meta charset="utf-8"><title>Input Type Mismatch</title></head>
4+
<body>
5+
<!-- "Contact email" is left as plain text: no native format
6+
validation, and a phone gets a full alphabetic keyboard instead
7+
of an email-optimized one. "Confirm email" is the correctly-wired
8+
case (same label wording, backed by type="email"), proving the
9+
check doesn't false-positive on a form that got it right.
10+
"Daytime phone" is the tel-guess true positive. "Comments" has no
11+
email/phone-looking label — irrelevant, should not be flagged. -->
12+
<form>
13+
<label for="email">Contact email</label>
14+
<input id="email" name="email" type="text">
15+
16+
<label for="email2">Confirm email</label>
17+
<input id="email2" name="email2" type="email">
18+
19+
<label for="phone">Daytime phone</label>
20+
<input id="phone" name="phone" type="text">
21+
22+
<label for="comments">Comments</label>
23+
<textarea id="comments" name="comments"></textarea>
24+
25+
<button type="submit">Submit</button>
26+
</form>
27+
</body>
28+
</html>

‎src/checks.rs‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,71 @@ pub async fn check_autofill_hints(page: &Page) -> Result<CheckResult> {
918918
))
919919
}
920920

921+
/// Guesses a field's semantic purpose from its label the same way
922+
/// [`check_autofill_hints`] does, but checks the `type` attribute instead
923+
/// of `autocomplete`: a field that looks like an email address or phone
924+
/// number and is left as `type="text"` (or untyped, which is the same
925+
/// thing) gets no native format validation, and on a phone the wrong
926+
/// virtual keyboard — a full alphabetic layout instead of an
927+
/// email-optimized or numeric-telephone one — a real mobile-usability
928+
/// cost for exactly the kind of form people fill out on their phone.
929+
/// Scoped to email/phone only: both have a well-supported dedicated
930+
/// `type` and an unambiguous label pattern, unlike e.g. a ZIP code (where
931+
/// `type="number"` would actively be wrong — it strips a leading zero
932+
/// and adds spinner arrows). A heuristic guess from label wording, like
933+
/// autofill hints, so a mismatch is a `Warn`, not a `Fail`.
934+
pub async fn check_input_type_mismatch(page: &Page) -> Result<CheckResult> {
935+
let mismatches: Vec<String> = page
936+
.evaluate(format!(
937+
r#"(() => {{
938+
const emailGuess = /e-?mail/i;
939+
const telGuess = /telephone|phone|mobile|cell|fax/i;
940+
const f = {TARGET_FORM_JS};
941+
const fields = f ? ({DEEP_QUERY_JS})(f, 'input[type=text], input:not([type])') : [];
942+
const labelOf = (el) => {{
943+
const byFor = el.id
944+
&& ({DEEP_QUERY_JS})(document, 'label').find((l) => l.htmlFor === el.id)?.textContent;
945+
const byWrap = el.closest('label')?.textContent;
946+
return (byFor || byWrap || el.name || el.id || '').trim();
947+
}};
948+
const mismatches = [];
949+
for (const el of fields) {{
950+
if (el.disabled || el.offsetParent === null) continue;
951+
const label = labelOf(el);
952+
if (!label) continue;
953+
if (emailGuess.test(label)) mismatches.push('email: ' + label.slice(0, 60));
954+
else if (telGuess.test(label)) mismatches.push('tel: ' + label.slice(0, 60));
955+
}}
956+
return mismatches;
957+
}})()"#
958+
))
959+
.await?
960+
.into_value()?;
961+
962+
let status = if mismatches.is_empty() {
963+
Status::Pass
964+
} else {
965+
Status::Warn
966+
};
967+
Ok(result(
968+
"Input type mismatch",
969+
status,
970+
if mismatches.is_empty() {
971+
"No field labeled like an email address or phone number is missing the matching \
972+
input type."
973+
.to_string()
974+
} else {
975+
format!(
976+
"{} field(s) look like an email address or phone number but use type=\"text\" \
977+
(or no type at all) — no native format validation, and the wrong keyboard on \
978+
mobile: {}.",
979+
mismatches.len(),
980+
mismatches.join(", ")
981+
)
982+
},
983+
))
984+
}
985+
921986
/// Flags form controls that share a `name` attribute with something they
922987
/// shouldn't. Standard form encoding keeps only one value (or silently
923988
/// merges them in a way the server likely doesn't expect) for a repeated
@@ -1334,6 +1399,14 @@ pub async fn run_all_with(page: &Page, opts: &RunOptions) -> Vec<CheckResult> {
13341399
check_autofill_hints(page),
13351400
)
13361401
.await,
1402+
run_safely(
1403+
page,
1404+
"Input type mismatch",
1405+
check_timeout,
1406+
capture,
1407+
check_input_type_mismatch(page),
1408+
)
1409+
.await,
13371410
run_safely(
13381411
page,
13391412
"Input persistence",

‎tests/checks_test.rs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,3 +855,48 @@ async fn form_with_no_required_looking_labels_passes_the_mismatch_check() {
855855
.expect("check_required_indicator_mismatch");
856856
assert_eq!(result.status, checks::Status::Pass, "got: {result:?}");
857857
}
858+
859+
#[tokio::test]
860+
async fn email_and_phone_looking_labels_left_as_plain_text_are_a_warn() {
861+
// fixtures/input-type-mismatch-form.html's "Contact email" and
862+
// "Daytime phone" are both left as type="text" — no native format
863+
// validation, and the wrong virtual keyboard on mobile. "Confirm
864+
// email" has the identical email-guess label wording but is
865+
// correctly wired as type="email", proving no false positive on a
866+
// form that got it right; "Comments" matches neither guess and is
867+
// irrelevant to this check either way.
868+
let (_browser, page, _handle) = open_fixture("input-type-mismatch-form.html").await;
869+
let result = checks::check_input_type_mismatch(&page)
870+
.await
871+
.expect("check_input_type_mismatch");
872+
assert_eq!(result.status, checks::Status::Warn, "got: {result:?}");
873+
assert!(
874+
result.detail.contains("Contact email"),
875+
"got: {}",
876+
result.detail
877+
);
878+
assert!(
879+
result.detail.contains("Daytime phone"),
880+
"got: {}",
881+
result.detail
882+
);
883+
assert!(
884+
!result.detail.contains("Confirm email"),
885+
"the correctly-wired type=\"email\" field must not be flagged, got: {}",
886+
result.detail
887+
);
888+
assert!(
889+
!result.detail.contains("Comments"),
890+
"a field matching neither guess is irrelevant to this check, got: {}",
891+
result.detail
892+
);
893+
}
894+
895+
#[tokio::test]
896+
async fn form_with_no_email_or_phone_looking_labels_passes_the_type_check() {
897+
let (_browser, page, _handle) = open_fixture("test-form.html").await;
898+
let result = checks::check_input_type_mismatch(&page)
899+
.await
900+
.expect("check_input_type_mismatch");
901+
assert_eq!(result.status, checks::Status::Pass, "got: {result:?}");
902+
}

0 commit comments

Comments
 (0)