Skip to content

Commit c4e6688

Browse files
authored
Bug/missing square bracket escape gsm7 (#367)
* Fix regex * Fixed regex by using character encoding * Composer didn't like php-http discovery
1 parent 84ab3b6 commit c4e6688

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
},
3636
"config": {
3737
"optimize-autoloader": true,
38-
"preferred-install": "dist"
38+
"preferred-install": "dist",
39+
"allow-plugins": {
40+
"php-http/discovery": true
41+
}
3942
},
4043
"autoload": {
4144
"psr-4": {

src/SMS/Message/SMS.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class SMS extends OutboundMessage
1515
{
16-
public const GSM_7_PATTERN = '/\A[\n\f\r !\"\#$%&\'()*+,-.\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\\^_abcdefghijklmnopqrstuvwxyz{\|}~ ¡£¤¥§¿ÄÅÆÇÉÑÖØÜßàäåæèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€]*\z/m';
16+
public const GSM_7_CHARSET = "\n\f\r !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~ ¡£¤¥§¿ÄÅÆÇÉÑÖØÜßàäåæèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€";
1717

1818
protected ?string $contentId;
1919

@@ -32,7 +32,8 @@ public function __construct(string $to, string $from, protected string $message,
3232

3333
public static function isGsm7(string $message): bool
3434
{
35-
return (bool)preg_match(self::GSM_7_PATTERN, $message);
35+
$fullPattern = "/\A[" . preg_quote(self::GSM_7_CHARSET, '/') . "]*\z/";
36+
return (bool)preg_match($fullPattern, $message);
3637
}
3738

3839
public function getContentId(): string
@@ -68,7 +69,7 @@ public function getErrorMessage(): ?string
6869

6970
if ($this->getType() === 'text' && ! self::isGsm7($this->getMessage())) {
7071
$this->setErrorMessage("You are sending a message as `text` when contains unicode only
71-
characters. This could result in encoding problems with the target device or increased billing - See
72+
characters. This could result in encoding problems with the target device - See
7273
https://developer.vonage.com/messaging/sms for details, or email support@vonage.com if you have any
7374
questions.");
7475
}

test/SMS/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public function testThrowsWarningWhenSendingUnicodeAsText(): void
413413

414414
$this->expectWarning();
415415
$this->expectErrorMessage("You are sending a message as `text` when contains unicode only
416-
characters. This could result in encoding problems with the target device or increased billing - See
416+
characters. This could result in encoding problems with the target device - See
417417
https://developer.vonage.com/messaging/sms for details, or email support@vonage.com if you have any
418418
questions.");
419419

test/SMS/Message/SMSTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public function unicodeStringDataProvider(): array
182182
{
183183
return [
184184
['this is a text', true],
185+
['This is a text with some tasty characters: [test]', true],
185186
['This is also a GSM7 text', true],
186187
['This is a Çotcha', true],
187188
['This is also a çotcha', true],

0 commit comments

Comments
 (0)