Skip to content

Commit

Permalink
#1005: Fixing sms number truncate bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
abpai94 authored and coudot committed Jan 6, 2025
1 parent 7e38373 commit ba318be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions htdocs/sendsms.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
$phone = sanitize_number($phone);
}
if ($sms_truncate_number) {
$phone = truncate_number($phone);
$phone = truncate_number($phone, $sms_truncate_number_length);
}
}else{
$result = "smsrequired";
Expand Down Expand Up @@ -138,6 +138,7 @@
$ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
$ldap_fullname_attribute, $sms_attributes,
$sms_sanitize_number, $sms_truncate_number,
$sms_truncate_number_length,
$obscure_notfound_sendsms, $token,
$keyphrase, $login);
if (!$result) { $result = "sendsms"; }
Expand Down Expand Up @@ -168,6 +169,7 @@
$ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
$ldap_fullname_attribute, $sms_attributes,
$sms_sanitize_number, $sms_truncate_number,
$sms_truncate_number_length,
$obscure_notfound_sendsms, $token,
$keyphrase, $login);
if ($sms){
Expand Down Expand Up @@ -348,7 +350,7 @@ function sanitize_number($phone_number){
return $phone_number;
}

function truncate_number($phone_number){
function truncate_number($phone_number, $sms_truncate_number_length){
$phone_number = substr($phone_number, -$sms_truncate_number_length);
return $phone_number;
}
Expand All @@ -357,6 +359,7 @@ function truncate_number($phone_number){
function get_user_infos($ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
$ldap_fullname_attribute, $sms_attributes,
$sms_sanitize_number, $sms_truncate_number,
$sms_truncate_number_length,
$obscure_notfound_sendsms, $token,
$keyphrase, $login) {

Expand Down Expand Up @@ -407,7 +410,7 @@ function get_user_infos($ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
$sms = sanitize_number($sms);
}
if ($sms_truncate_number) {
$sms = truncate_number($sms);
$sms = truncate_number($sms, $sms_truncate_number_length);
}
}else{
list($result, $token) = obscure_info_sendsms("smssent_ifexists",
Expand Down
28 changes: 28 additions & 0 deletions tests/sendsmsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

require_once __DIR__ . '/../htdocs/sendsms.php';

class sendsmsTest extends \PHPUnit\Framework\TestCase
{
public function testsmstruncate1()
{
$sms_truncate_number_length = 10;
$result = truncate_number("12345678901", $sms_truncate_number_length);
$this->assertEquals("2345678901", $result);
}


public function testsmstruncate2()
{
$sms_truncate_number_length = 9;
$result = truncate_number("12345678901", $sms_truncate_number_length);
$this->assertEquals("345678901", $result);
}

public function testsmstruncate3()
{
$sms_truncate_number_length = 0;
$result = truncate_number("12345678901", $sms_truncate_number_length);
$this->assertEquals("12345678901", $result);
}
}

0 comments on commit ba318be

Please sign in to comment.