tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 763939bd51f7c780aa429e835ef1e61cb699f862
parent 222bb67dc8270ca15bf11c3e3d51d7765bb2db24
Author: Jonathan Kew <jkew@mozilla.com>
Date:   Wed, 17 Dec 2025 12:17:24 +0000

Bug 1670462 - Ignore leading/trailing whitespace when validating <input type=email>. r=hsivonen

It seems we already trim whitespace for <input type=email multiple>, just not for
single-email inputs.

Experimenting with https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/form
shows that if we allow leading/trailing whitespace here, it's still trimmed from the value
when submitting the form.

Differential Revision: https://phabricator.services.mozilla.com/D276640

Diffstat:
Mdom/html/input/SingleLineTextInputTypes.cpp | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/dom/html/input/SingleLineTextInputTypes.cpp b/dom/html/input/SingleLineTextInputTypes.cpp @@ -179,14 +179,17 @@ bool EmailInputType::IsValidEmailAddressList(const nsAString& aValue) { /* static */ bool EmailInputType::IsValidEmailAddress(const nsAString& aValue) { + nsAutoString trimmed(aValue); + trimmed.Trim(" \n\r\t\f"); + // Email addresses can't be empty and can't end with a '.' or '-'. - if (aValue.IsEmpty() || aValue.Last() == '.' || aValue.Last() == '-') { + if (trimmed.IsEmpty() || trimmed.Last() == '.' || trimmed.Last() == '-') { return false; } uint32_t atPos; nsAutoCString value; - if (!PunycodeEncodeEmailAddress(aValue, value, &atPos) || + if (!PunycodeEncodeEmailAddress(trimmed, value, &atPos) || atPos == (uint32_t)kNotFound || atPos == 0 || atPos == value.Length() - 1) { // Could not encode, or "@" was not found, or it was at the start or end