mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-24 14:24:15 +00:00
fixed bug in phone number verification
* allow whitespaces in phone number see #743
This commit is contained in:
parent
221762b935
commit
7222b931ae
@ -144,7 +144,7 @@ COPY src/plugin_loader.go /tmp/signal-cli-rest-api-src/
|
||||
RUN ls -la /tmp/signal-cli-rest-api-src
|
||||
RUN cd /tmp/signal-cli-rest-api-src && ${GOPATH}/bin/swag init
|
||||
RUN cd /tmp/signal-cli-rest-api-src && go build -o signal-cli-rest-api main.go
|
||||
RUN cd /tmp/signal-cli-rest-api-src && go test ./client -v
|
||||
RUN cd /tmp/signal-cli-rest-api-src && go test ./client -v && go test ./utils -v
|
||||
|
||||
# build supervisorctl_config_creator
|
||||
RUN cd /tmp/signal-cli-rest-api-src/scripts && go build -o jsonrpc2-helper
|
||||
|
||||
@ -41,7 +41,7 @@ func IsPhoneNumber(s string) bool {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if c < '0' || c > '9' {
|
||||
if (c < '0' || c > '9') && (c != ' ') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
42
src/utils/utils_test.go
Normal file
42
src/utils/utils_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func expectEqual(t *testing.T, in1 bool, in2 bool) {
|
||||
if in1 != in2 {
|
||||
t.Errorf("got %t, wanted %t", in1, in2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsPhoneNumber(t *testing.T) {
|
||||
res := IsPhoneNumber("+12345678")
|
||||
expectEqual(t, res, true)
|
||||
}
|
||||
|
||||
|
||||
func TestIsPhoneNumberWithSpaces(t *testing.T) {
|
||||
res := IsPhoneNumber("+ 12345678")
|
||||
expectEqual(t, res, true)
|
||||
}
|
||||
|
||||
func TestIsPhoneNumberWithSpaces1(t *testing.T) {
|
||||
res := IsPhoneNumber("+ 1234 5678")
|
||||
expectEqual(t, res, true)
|
||||
}
|
||||
|
||||
func TestIsPhoneNumberWithInvalidCharacters(t *testing.T) {
|
||||
res := IsPhoneNumber("+123456x")
|
||||
expectEqual(t, res, false)
|
||||
}
|
||||
|
||||
func TestIsPhoneNumberWithMissingPrefix(t *testing.T) {
|
||||
res := IsPhoneNumber("123456x")
|
||||
expectEqual(t, res, false)
|
||||
}
|
||||
|
||||
func TestIsPhoneNumberWithInvalidCharactersAndSpaces(t *testing.T) {
|
||||
res := IsPhoneNumber("+12345 6x")
|
||||
expectEqual(t, res, false)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user