-
Notifications
You must be signed in to change notification settings - Fork 5
fix: straddle message bug #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,12 +162,17 @@ private function inspect(string $messageContent): void | |
| // Any character outside the 7-bit alphabet switches the entire encoding to UCS-2 | ||
| $this->encoding = '7-bit'; | ||
| $this->size = 0; | ||
|
|
||
| $mbLength = mb_strlen($messageContent, 'UTF-8'); | ||
| for ($i = 0; $i < $mbLength; $i++) { | ||
| $char = mb_substr($messageContent, $i, 1, 'UTF-8'); | ||
| if (in_array($char, self::GSM0338_BASIC, true)) { | ||
| $this->size++; | ||
| } elseif (in_array($char, self::GSM0338_EXTENDED, true)) { | ||
| // In cases where a double counted char straddles two messages, add padding to push it to the next part | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be clearer to say why we need to count as 3; something like:
|
||
| if (($this->size + 2) % self::MAXIMUM_CHARACTERS_7BIT_CONCATENATED === 1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't verified this, but I'm concerned that if the extended character is encountered at pos 153 (so also using 154) in a message whose total length that is shorter than 160, this will be adding unnecessary size. E.g. number of characters is 159, one extended char at pos 153 with size counted as 3, pushes total size to 161 where actually it would be 160 and fit in a single message. There should be a test for this. |
||
| $this->size++; | ||
| } | ||
| $this->size += 2; | ||
| } else { | ||
| $this->encoding = 'ucs-2'; | ||
|
|
@@ -182,7 +187,14 @@ private function inspect(string $messageContent): void | |
| for ($i = 0; $i < $mbLength; $i++) { | ||
| $char = mb_substr($messageContent, $i, 1, 'UTF-8'); | ||
| $utf16Hex = bin2hex(mb_convert_encoding($char, 'UTF-16', 'UTF-8')); | ||
| $this->size += strlen($utf16Hex) / 4; | ||
| $charSize = strlen($utf16Hex) / 4; | ||
|
|
||
| // In cases where a double counted char straddles two messages, add padding to push it to the next part | ||
| if ($charSize > 1 && ($this->size + $charSize) % self::MAXIMUM_CHARACTERS_UCS2_CONCATENATED === 1) { | ||
| $this->size++; | ||
| } | ||
|
|
||
| $this->size += $charSize; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -196,7 +208,7 @@ private function inspect(string $messageContent): void | |
|
|
||
| $this->messageCount = 1; | ||
| if ($this->size > $singleSize) { | ||
| $this->messageCount = (int)ceil($this->size / $concatSize); | ||
| $this->messageCount = (int) ceil($this->size / $concatSize); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to commit a change here. |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to commit a change here.