Improve the replacement for wc_format_phone_number a bit more, seems like we allow spaces and plus signs, remove non visible unicode with seperate preg_replace
This commit is contained in:
parent
7a3caa0608
commit
2df62edec1
|
@ -941,7 +941,7 @@ function wc_normalize_postcode( $postcode ) {
|
|||
* @return string
|
||||
*/
|
||||
function wc_format_phone_number( $phone ) {
|
||||
return preg_replace( '/[^0-9\+]/', '', $phone );
|
||||
return preg_replace( '/[^0-9\+\-\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $phone ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -760,6 +760,8 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
*/
|
||||
public function test_wc_format_phone_number() {
|
||||
$this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) );
|
||||
$this->assertEquals( '+47 0000 00003', wc_format_phone_number( '+47 0000 00003' ) ); // This number contains non-visible unicode chars at the beginning and end of string, should remove all those.
|
||||
$this->assertEquals( '27 00 00 0000', wc_format_phone_number( '27 00 00 0000' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -894,7 +896,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
*/
|
||||
public function test_wc_do_oembeds() {
|
||||
// In this case should only return the URL back, since oEmbed will run other actions on frontend.
|
||||
$this->assertEquals( "<iframe width='500' height='281' src='https://videopress.com/embed/9sRCUigm?hd=0' frameborder='0' allowfullscreen></iframe><script src='https://v0.wordpress.com/js/next/videopress-iframe.js?m=1435166243'></script>", wc_do_oembeds( 'https://wordpress.tv/2015/10/19/mike-jolley-user-onboarding-for-wordpress-plugins/' ) );
|
||||
$this->assertEquals( "<iframe width='500' height='281' src='https://videopress.com/embed/9sRCUigm?hd=0' frameborder='0' allowfullscreen></iframe><script src='https://v0.wordpress.com/js/next/videopress-iframe.js?m=1435166243'></script>", wc_do_oembeds( 'https://wordpress.tv/2015/10/19/mike-jolley-user-onboarding-for-wordpress-plugins/' ) ); // phpcs:ignore
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue