mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Stop escaping special characters in inbound
At least one of our providers gives us messages with special characters escaped, ie a newline comes through as `\n`, not a literal newline. We shouldn’t be showing these backslashes to any of our users. Python has built in codecs for dealing with encoding/decoding of strings – see https://docs.python.org/3/library/codecs.html#text-encodings for details. Using these builtins is safer than trying to do anything regex or parsing-based.
This commit is contained in:
@@ -133,6 +133,6 @@ def get_sms_thread(service_id, user_number):
|
||||
|
||||
def get_sms_content(notification, is_inbound):
|
||||
return (
|
||||
notification['content'] if is_inbound else
|
||||
bytes(notification['content'], "utf-8").decode('unicode_escape') if is_inbound else
|
||||
notification['template']['content']
|
||||
)
|
||||
|
||||
@@ -203,6 +203,9 @@ def get_inbox_partials(service_id):
|
||||
format_phone_number_human_readable(message['user_number'])
|
||||
for message in messages_to_show
|
||||
}:
|
||||
message.update({
|
||||
'content': bytes(message['content'], 'utf-8').decode('unicode_escape')
|
||||
})
|
||||
messages_to_show.append(message)
|
||||
|
||||
if not inbound_messages:
|
||||
|
||||
Reference in New Issue
Block a user