Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 118.0.2

* Fix small bug in counting length of text messages with non-GSM and extended GSM characters

## 118.0.1

* Improve performance of `Field.placeholders`
Expand Down
19 changes: 9 additions & 10 deletions notifications_utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,25 @@ def content_count_without_prefix(self):

@property
def fragment_count(self):
# Extended GSM characters count as 2 characters
character_count = self.content_count + self.count_extended_gsm_chars

if self.non_gsm_characters:
return 1 if character_count <= 70 else math.ceil(float(character_count) / 67)
return 1 if self.content_count <= 70 else math.ceil(float(self.content_count) / 67)

# Extended GSM characters count as 2 characters in GSM-7
character_count = self.content_count + self.count_extended_gsm_chars

return 1 if character_count <= 160 else math.ceil(float(character_count) / 153)

@property
def count_of_characters_above_previous_fragment_boundary(self):
character_count = self.content_count + self.count_extended_gsm_chars

if self.fragment_count == 1:
boundary = 0
elif self.fragment_count == 2:
if self.fragment_count == 2:
boundary = 70 if self.non_gsm_characters else 160
else:
boundary = (67 if self.non_gsm_characters else 153) * (self.fragment_count - 1)

return character_count - boundary
if self.non_gsm_characters:
return self.content_count - boundary

return self.content_count + self.count_extended_gsm_chars - boundary

@property
def non_gsm_characters(self):
Expand Down
2 changes: 1 addition & 1 deletion notifications_utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# - `make version-minor` for new features
# - `make version-patch` for bug fixes

__version__ = "118.0.1" # 25047862539d5613bcec377a6ff40354
__version__ = "118.0.2" # 75ca400e566fa067cf59d21e92107e23
7 changes: 5 additions & 2 deletions tests/test_template_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,15 +1102,18 @@ def test_sms_fragment_count_accounts_for_unicode_and_welsh_characters(
"template_content, expected_sms_fragment_count, expected_count_of_characters_above_previous_fragment_boundary",
[
# all extended GSM characters
("^" * 80, 1, 160),
("^" * 81, 2, 2),
# GSM characters plus extended GSM
("a" * 158 + "|", 1, 160),
("a" * 159 + "|", 2, 1),
("a" * 304 + "[", 2, 146),
("a" * 304 + "[]", 3, 2),
# Welsh character plus extended GSM
("â" * 132 + "{", 2, 64),
("â" * 133 + "}", 3, 1),
("â" * 69 + "{", 1, 70),
("â" * 70 + "{", 2, 1),
("â" * 133 + "}", 2, 64),
("â" * 134 + "}", 3, 1),
# Non-GSM or extended characters in placeholder, not content
("a" * 160 + "(( placeholder with â ))", 1, 160),
("a" * 160 + "(( placeholder with | ))", 1, 160),
Expand Down
Loading