Skip to content

Commit e6aca7a

Browse files
committed
ltb-project#1005: Fixing sms number truncate bug.
1 parent ceb132b commit e6aca7a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

htdocs/sendsms.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
$phone = sanitize_number($phone);
5555
}
5656
if ($sms_truncate_number) {
57-
$phone = truncate_number($phone);
57+
$phone = truncate_number($phone, $sms_truncate_number_length);
5858
}
5959
}else{
6060
$result = "smsrequired";
@@ -138,6 +138,7 @@
138138
$ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
139139
$ldap_fullname_attribute, $sms_attributes,
140140
$sms_sanitize_number, $sms_truncate_number,
141+
$sms_truncate_number_length,
141142
$obscure_notfound_sendsms, $token,
142143
$keyphrase, $login);
143144
if (!$result) { $result = "sendsms"; }
@@ -168,6 +169,7 @@
168169
$ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
169170
$ldap_fullname_attribute, $sms_attributes,
170171
$sms_sanitize_number, $sms_truncate_number,
172+
$sms_truncate_number_length,
171173
$obscure_notfound_sendsms, $token,
172174
$keyphrase, $login);
173175
if ($sms){
@@ -348,7 +350,7 @@ function sanitize_number($phone_number){
348350
return $phone_number;
349351
}
350352

351-
function truncate_number($phone_number){
353+
function truncate_number($phone_number, $sms_truncate_number_length){
352354
$phone_number = substr($phone_number, -$sms_truncate_number_length);
353355
return $phone_number;
354356
}
@@ -357,6 +359,7 @@ function truncate_number($phone_number){
357359
function get_user_infos($ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
358360
$ldap_fullname_attribute, $sms_attributes,
359361
$sms_sanitize_number, $sms_truncate_number,
362+
$sms_truncate_number_length,
360363
$obscure_notfound_sendsms, $token,
361364
$keyphrase, $login) {
362365

@@ -407,7 +410,7 @@ function get_user_infos($ldapInstance, $ldap_base, $ldap_filter, $ldap_scope,
407410
$sms = sanitize_number($sms);
408411
}
409412
if ($sms_truncate_number) {
410-
$sms = truncate_number($sms);
413+
$sms = truncate_number($sms, $sms_truncate_number_length);
411414
}
412415
}else{
413416
list($result, $token) = obscure_info_sendsms("smssent_ifexists",

tests/sendsmsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../htdocs/sendsms.php';
4+
5+
class sendsmsTest extends \PHPUnit\Framework\TestCase
6+
{
7+
public function testsmstruncate1()
8+
{
9+
$sms_truncate_number_length = 10;
10+
$result = truncate_number("12345678901", $sms_truncate_number_length);
11+
$this->assertEquals("2345678901", $result);
12+
}
13+
14+
15+
public function testsmstruncate2()
16+
{
17+
$sms_truncate_number_length = 9;
18+
$result = truncate_number("12345678901", $sms_truncate_number_length);
19+
$this->assertEquals("345678901", $result);
20+
}
21+
22+
public function testsmstruncate3()
23+
{
24+
$sms_truncate_number_length = 0;
25+
$result = truncate_number("12345678901", $sms_truncate_number_length);
26+
$this->assertEquals("12345678901", $result);
27+
}
28+
}

0 commit comments

Comments
 (0)