From c6b884dcefbc094d080aaa98053f144b157c16f1 Mon Sep 17 00:00:00 2001 From: David McDonald Date: Fri, 29 Oct 2021 16:10:55 +0100 Subject: [PATCH] Upgrade utils to 48.0.0 Fixes a bug with non breaking spaces being removed from templates --- app/__init__.py | 7 +++++-- app/main/forms.py | 6 +++--- app/models/contact_list.py | 4 ++-- .../views/service-settings/letter-contact-details.html | 2 +- requirements.in | 2 +- requirements.txt | 2 +- tests/app/main/views/test_send.py | 4 ++-- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 0a60270cc..ff1880710 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -24,7 +24,10 @@ from govuk_frontend_jinja.flask_ext import init_govuk_frontend from itsdangerous import BadSignature from notifications_python_client.errors import HTTPError from notifications_utils import logging, request_helper -from notifications_utils.formatters import formatted_list, normalise_lines +from notifications_utils.formatters import ( + formatted_list, + get_lines_with_normalised_whitespace, +) from notifications_utils.recipients import format_phone_number_human_readable from notifications_utils.sanitise_text import SanitiseASCII from werkzeug.exceptions import HTTPException as WerkzeugHTTPException @@ -553,7 +556,7 @@ def add_template_filters(application): format_notification_status_as_url, format_number_in_pounds_as_currency, formatted_list, - normalise_lines, + get_lines_with_normalised_whitespace, nl2br, format_phone_number_human_readable, format_thousands, diff --git a/app/main/forms.py b/app/main/forms.py index 15dddedec..f9d73d469 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -11,7 +11,7 @@ from flask_wtf.file import FileAllowed from flask_wtf.file import FileField as FileField_wtf from notifications_utils.columns import Columns from notifications_utils.countries.data import Postage -from notifications_utils.formatters import strip_whitespace +from notifications_utils.formatters import strip_all_whitespace from notifications_utils.postal_address import PostalAddress from notifications_utils.recipients import ( InvalidPhoneError, @@ -551,7 +551,7 @@ class StripWhitespaceForm(Form): # FieldList simply doesn't support filters. # @see: https://github.com/wtforms/wtforms/issues/148 no_filter_fields = (FieldList, PasswordField, GovukPasswordField) - filters = [strip_whitespace] if not issubclass(unbound_field.field_class, no_filter_fields) else [] + filters = [strip_all_whitespace] if not issubclass(unbound_field.field_class, no_filter_fields) else [] filters += unbound_field.kwargs.get('filters', []) bound = unbound_field.bind(form=form, filters=filters, **options) bound.get_form = weakref.ref(form) # GC won't collect the form if we don't use a weakref @@ -567,7 +567,7 @@ class StripWhitespaceStringField(GovukTextInputField): kwargs['filters'] = tuple(chain( kwargs.get('filters', ()), ( - strip_whitespace, + strip_all_whitespace, ), )) super(GovukTextInputField, self).__init__(label, **kwargs) diff --git a/app/models/contact_list.py b/app/models/contact_list.py index 870ef80de..6bd104510 100644 --- a/app/models/contact_list.py +++ b/app/models/contact_list.py @@ -2,7 +2,7 @@ from functools import partial from os import path from flask import abort, current_app -from notifications_utils.formatters import strip_whitespace +from notifications_utils.formatters import strip_all_whitespace from notifications_utils.recipients import RecipientCSV from werkzeug.utils import cached_property @@ -56,7 +56,7 @@ class ContactList(JSONModel): @staticmethod def download(service_id, upload_id): - return strip_whitespace(s3download( + return strip_all_whitespace(s3download( service_id, upload_id, bucket=ContactList.get_bucket_name(), diff --git a/app/templates/views/service-settings/letter-contact-details.html b/app/templates/views/service-settings/letter-contact-details.html index 3ae2021c3..fdd9c8aba 100644 --- a/app/templates/views/service-settings/letter-contact-details.html +++ b/app/templates/views/service-settings/letter-contact-details.html @@ -58,7 +58,7 @@ {% if letter_contact_details|length > 1 %} - {% set first_line_of_contact_block = item.contact_block|normalise_lines|first %} + {% set first_line_of_contact_block = item.contact_block|get_lines_with_normalised_whitespace|first %} {{ copy_to_clipboard(item.id, name=first_line_of_contact_block, thing="ID") }} {% endif %} diff --git a/requirements.in b/requirements.in index d26330268..2f7d59830 100644 --- a/requirements.in +++ b/requirements.in @@ -28,7 +28,7 @@ importlib-metadata==4.2.0 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 # pyup: <2 -git+https://github.com/alphagov/notifications-utils.git@47.0.1#egg=notifications-utils==47.0.1 +git+https://github.com/alphagov/notifications-utils.git@48.0.0#egg=notifications-utils==48.0.0 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.8-alpha#egg=govuk-frontend-jinja==0.5.8-alpha # cryptography 3.4+ incorporates Rust code, which isn't supported on PaaS diff --git a/requirements.txt b/requirements.txt index 84e2947c5..e6be4aec3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -125,7 +125,7 @@ mistune==0.8.4 # via notifications-utils notifications-python-client==6.3.0 # via -r requirements.in -notifications-utils @ git+https://github.com/alphagov/notifications-utils.git@47.0.1 +notifications-utils @ git+https://github.com/alphagov/notifications-utils.git@48.0.0 # via -r requirements.in openpyxl==3.0.7 # via pyexcel-xlsx diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 4e7f6c32f..cb96f8cbc 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -2295,8 +2295,8 @@ def test_send_one_off_letter_address_shows_form( }), # it ignores empty lines and strips whitespace from each line. # It also strips extra whitespace from the middle of lines. - ('\n a\ta \n\n\n \n\n\n\nb b \r\n sw1a1aa \n\n', { - 'address_line_1': 'a\ta', + ('\n a\ta \n\n\n \n\n\n\nb b \r\n sw1a\u00A01aa \n\n', { + 'address_line_1': 'a a', 'address_line_2': 'b b', 'address_line_3': '', 'address_line_4': '',