mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-02 22:20:44 -05:00
Merge pull request #1378 from alphagov/fix-escaping-mmg-inbound
Fix escaping in inbound text messages from MMG
This commit is contained in:
@@ -82,7 +82,11 @@ def receive_firetext_sms():
|
||||
|
||||
|
||||
def format_mmg_message(message):
|
||||
return unquote(message.replace('+', ' '))
|
||||
return unescape_string(unquote(message.replace('+', ' ')))
|
||||
|
||||
|
||||
def unescape_string(string):
|
||||
return string.encode('raw_unicode_escape').decode('unicode_escape')
|
||||
|
||||
|
||||
def format_mmg_datetime(date):
|
||||
|
||||
@@ -12,6 +12,7 @@ from app.notifications.receive_notifications import (
|
||||
create_inbound_sms_object,
|
||||
strip_leading_forty_four,
|
||||
has_inbound_sms_permissions,
|
||||
unescape_string,
|
||||
)
|
||||
|
||||
from app.models import InboundSms, EMAIL_TYPE, SMS_TYPE, INBOUND_SMS_TYPE
|
||||
@@ -166,6 +167,36 @@ def test_format_mmg_message(message, expected_output):
|
||||
assert format_mmg_message(message) == expected_output
|
||||
|
||||
|
||||
@pytest.mark.parametrize('raw, expected', [
|
||||
(
|
||||
'😬',
|
||||
'😬',
|
||||
),
|
||||
(
|
||||
'1\\n2',
|
||||
'1\n2',
|
||||
),
|
||||
(
|
||||
'\\\'"\\\'',
|
||||
'\'"\'',
|
||||
),
|
||||
(
|
||||
"""
|
||||
|
||||
""",
|
||||
"""
|
||||
|
||||
""",
|
||||
),
|
||||
(
|
||||
'\x79 \\x79 \\\\x79', # we should never see the middle one
|
||||
'y y \\x79',
|
||||
),
|
||||
])
|
||||
def test_unescape_string(raw, expected):
|
||||
assert unescape_string(raw) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('provider_date, expected_output', [
|
||||
('2017-01-21+11%3A56%3A11', datetime(2017, 1, 21, 11, 56, 11)),
|
||||
('2017-05-21+11%3A56%3A11', datetime(2017, 5, 21, 10, 56, 11))
|
||||
|
||||
Reference in New Issue
Block a user