There was an error while loading. Please reload this page.
1 parent f05c8ab commit 27ef4acCopy full SHA for 27ef4ac
4 files changed
.github/actions/waffles/requirements.txt
@@ -2,4 +2,4 @@ docopt==0.6.2
2
Flask==2.3.3
3
markupsafe==2.1.5
4
setuptools==78.1.1 # required for distutils in Python 3.12
5
-git+https://github.com/cds-snc/notifier-utils.git@53.2.20#egg=notifications-utils
+git+https://github.com/cds-snc/notifier-utils.git@53.2.21#egg=notifications-utils
notifications_utils/template.py
@@ -211,11 +211,14 @@ def _encoded_content(self):
211
When values are set, placeholders are already replaced via __str__. When no values are
212
set, placeholder syntax is stripped before encoding so that placeholder names don't
213
inflate the character count or skew Unicode detection.
214
+
215
+ normalise_newlines is applied in both paths so that CRLF sequences (\\r\\n) submitted by
216
+ browsers are counted as a single newline unit, matching what is actually transmitted.
217
"""
218
if self._values:
219
# we always want to call SMSMessageTemplate.__str__ regardless of subclass, to avoid any html formatting
220
return SMSMessageTemplate.__str__(self)
- return sms_encode(add_prefix(Field.placeholder_pattern.sub("", self.content.strip()), self.prefix))
221
+ return normalise_newlines(sms_encode(add_prefix(Field.placeholder_pattern.sub("", self.content.strip()), self.prefix)))
222
223
@property
224
def content_count(self):
pyproject.toml
@@ -1,6 +1,6 @@
1
[tool.poetry]
name = "notifications-utils"
-version = "53.2.20"
+version = "53.2.21"
description = "Shared python code for Notification - Provides logging utils etc."
authors = ["Canadian Digital Service"]
6
license = "MIT license"
tests/test_base_template.py
@@ -78,8 +78,15 @@ def test_extracting_placeholders(template_content, template_subject, expected):
78
# should be replaced with a ?
79
("深", None, 1, 1),
80
("'First line.\n", None, 12, 12),
81
- ("\t\n\r", None, 0, 0),
82
- # variables do not count towards the character count for sms, since they will be replaced
+ ("\t\n\r", None, 0, 0), # CRLF newlines (\r\n) from browser form submissions must be normalised to \n
+ # before counting, so each line break costs exactly 1 unit (not 2).
83
+ ("Hello\r\nWorld", None, 11, 11),
84
+ (
85
+ "Line1\r\nLine2\r\nLine3",
86
+ None,
87
+ 17,
88
89
+ ), # variables do not count towards the character count for sms, since they will be replaced
90
("((placeholder))", None, 0, 3),
91
("((placeholder))", "Service name", 14, 17),
92
("Foo", "((placeholder))", 20, 20), # placeholder doesn’t work in service name
0 commit comments