Validator should check if it is being called on a user entity

Created on 10 March 2024, 10 months ago
Updated 26 March 2024, 9 months ago

Problem/Motivation

A programmer could apply the AlternativeUserEmailsValidator to a non-user entity. This will have unexpected results because the validator does not check to see if it is operating on a user entity. (It used to, but this check was mistakenly removed 🐛 Fix broken validation (core's email validator does not check alternative emails) Fixed . The check is necessary because the validator uses the entity id as the user ID to exclude the current user from the query, so if the entity is not a user entity, the wrong ID will be used.)

I propose not only restoring the check but renaming the variables to make it clear this is a $user, not a generic $entity, and throwing exceptions if the fundamental criteria for running the validator are not met. Silently failing is dangerous if a programmer expects validation and no error is returned, and these exceptions can only be triggered by programmers applying the validator to new code.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇯🇵Japan ptmkenny

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024