-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1841 from betagouv/master
MEP TRELLO-2865 sanitize incoming phone in reports
- Loading branch information
Showing
3 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package utils | ||
|
||
object PhoneNumberUtils { | ||
|
||
def sanitizeIncomingPhoneNumber(phone: String): String = | ||
phone | ||
// remove all spaces | ||
.replaceAll("\\s+", "") | ||
// remove all dots | ||
.replaceAll("\\.+", "") | ||
// Replace french indicator format +33X or 0033X by just the classic 0X | ||
.replaceFirst("^\\+33", "0") | ||
.replaceFirst("^0033", "0") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package utils | ||
|
||
import org.specs2.mutable.Specification | ||
import utils.PhoneNumberUtils.sanitizeIncomingPhoneNumber | ||
|
||
class PhoneNumberUtilsSpec extends Specification { | ||
"PhoneNumberUtils" should { | ||
|
||
"leave typical phone number as is" in { | ||
sanitizeIncomingPhoneNumber("0545653312") shouldEqual "0545653312" | ||
} | ||
|
||
"leave typical small phone number as is" in { | ||
sanitizeIncomingPhoneNumber("3605") shouldEqual "3605" | ||
} | ||
|
||
"remove spaces" in { | ||
sanitizeIncomingPhoneNumber("05 45 65 33 12") shouldEqual "0545653312" | ||
} | ||
|
||
"remove dots" in { | ||
sanitizeIncomingPhoneNumber("05.45.65.33.12") shouldEqual "0545653312" | ||
} | ||
|
||
"remove +33" in { | ||
sanitizeIncomingPhoneNumber("+33545653312") shouldEqual "0545653312" | ||
} | ||
|
||
"remove 0033" in { | ||
sanitizeIncomingPhoneNumber("0033545653312") shouldEqual "0545653312" | ||
} | ||
|
||
"remove a combination of all of that" in { | ||
sanitizeIncomingPhoneNumber(" +33 5 45.65.33. 12 ") shouldEqual "0545653312" | ||
} | ||
|
||
} | ||
} |