- Issue created by @Shamrockonov
This is very particularly like 🐛 Unhandled exception when trying to register a duplicate username with different case Needs review .
- Assigned to larowlan
- Issue was unassigned.
- Status changed to Needs review
over 1 year ago 10:02pm 7 February 2024 - 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
Was expecting this would also impact username, as it also uses that constraint - but we have a unique key on name for the users table, so instead if causes a fatal (SQL) exception - so still an issue.
Added tests and fix for both cases.
- Assigned to divya.sejekan
- 🇮🇳India divya.sejekan
I verified for the use cases given above. The fix is working - Error message are displayed 'The email address EMAIL@TEST.COM is already taken.'
Testing Steps :
1. Creating user with Email@test.com
2. Verify when used different cases such as eMail@test.com , EMAIL@test.com - error message must be displayed
3. Verify when used same case Email@test.com with different usernames - - error message must be displayedCan be moved to RTBC++
Keeping this in need review for further reviews.
- Issue was unassigned.
- Status changed to Needs work
over 1 year ago 5:40pm 8 February 2024 - 🇺🇸United States smustgrave
Opened an MR and appears to have test failures.
- 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
🐛 Unhandled exception when trying to register a duplicate username with different case Needs review is in so let's repurpose this
- 🇺🇸United States caesius
This appears to have been added in the latest core security update:
https://www.drupal.org/sa-core-2024-004 →
https://git.drupalcode.org/project/drupal/-/commit/f1d3470b057e84fd5483b...
- Status changed to Postponed: needs info
3 days ago 10:35am 3 June 2025 - 🇬🇧United Kingdom jamsilver West Midlands, UK
A comment here that may save others time.
Today, I added the
UniqueField
constraint onto a base field on a custom entity type, settingcaseSensitive
to TRUE, and found that it did not work. I created a new entity and entered a value for this field that matched an existing value, except for a change in the case of a single letter (e.g. "bar" vs "Bar"). This validator rejected the new entity. but I would have expected it to accept it.As it happens, my field is a
string
type, so I was able to set thecase_sensitive
field option to force the SQL field storage to store it in a format that always behaves case-sensitively in queries. All in all, this is the sort of base field definition I now have:$fields['foo'] = BaseFieldDefinition::create('string') ->setTranslatable(FALSE) ->setLabel(t('Foo')) ->setRequired(TRUE) ->addConstraint('UniqueField', ['caseSensitive' => TRUE]) ->setSetting('case_sensitive', TRUE) ->setSetting('max_length', 255);
It may be relevant that I'm using MariaDB (version 10.4) rather than MySQL.
On balance this feels to me like unexpected behaviour in the
UniqueField
Constraint that should be improved. There's nothing in the documentation of thecaseSensitive
option that indicates extra steps are necessary in the SQL storage to make it work.The UniqueFieldValueValidator uses an entity query, and entity query has supported case-sensitive comparisons since #2068655: Entity fields do not support case sensitive queries → . Perhaps a better implementation here would be to keep the OR condition when caseSensitive, but use the
LIKE BINARY
operator?