Make WordPress Core

Opened 5 years ago

Last modified 12 months ago

#47557 new enhancement

Sanitize Email Suggestion

Reported by: dandersoncm's profile dandersoncm Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.2.1
Component: Formatting Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

I am using WooCommerce and I've noticed several customer emails come through like...

example@example.com1234
example@example.com1234567812345678

It's mostly due to the email input being the last one before the credit card step, but these emails are passing the validation and sanitization that exists: is_email and sanitize_email.

I am doing something like the following to fix...

<?php

    public function clean_billing_email_address( $value ) {
        return trim( preg_replace( '/\d*$/', '', $value ) );
    }
    add_filter( 'woocommerce_process_checkout_field_billing_email', 'clean_billing_email_address' );

You may consider adding something like this to the sanitize_email function since no TLD ends with numbers anyways, at least at this point in time.

Change History (3)

#1 @mostafa.s1990
5 years ago

  • Keywords needs-patch added

#2 @SergeyBiryukov
5 years ago

  • Keywords needs-unit-tests added

#3 @bhubbard
12 months ago

Here is a test function:

<?php
public function test_clean_billing_email_address()
{
    $value = 'user123@example.com123';
    $expected = 'user123@example.com';
    $result = clean_billing_email_address($value);
    $this->assertEquals($expected, $result);

    $value = ' user456@example.com   ';
    $expected = 'user456@example.com';
    $result = clean_billing_email_address($value);
    $this->assertEquals($expected, $result);

    $value = ' user789@example.com 123';
    $expected = 'user789@example.com';
    $result = clean_billing_email_address($value);
    $this->assertEquals($expected, $result);
}
Note: See TracTickets for help on using tickets.