Skip to content

Commit

Permalink
Link Chooser - tel: links should prevent spaces
Browse files Browse the repository at this point in the history
- Added regex operation to strip out spaces
- See spec - tel: hrefs should not have spaces https://www.rfc-editor.org/rfc/rfc3966#section-3
- Fixes wagtail#10558
  • Loading branch information
Th0masCat authored and lb- committed Jul 3, 2023
1 parent 6491ae4 commit c7039ed
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog
* Add a predictable default ordering of the "Object/Other permissions" in the Group Editing view, allow this ordering to be customised (Daniel Kirkham)
* Add `AbstractImage.get_renditions()` for efficient generation of multiple renditions (Andy Babic)
* Optimise queries in collection permission policies using cache on the user object (Sage Abdullah)
* Phone numbers entered via a link chooser will now have any spaces stripped out, ensuring a valid href="tel:..." attribute (Sahil Jangra)
* Fix: Prevent choosers from failing when initial value is an unrecognised ID, e.g. when moving a page from a location where `parent_page_types` would disallow it (Dan Braghis)
* Fix: Move comment notifications toggle to the comments side panel (Sage Abdullah)
* Fix: Remove comment button on InlinePanel fields (Sage Abdullah)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@
* valnuro
* Vitaly Babiy
* Sébastien Corbin
* Sahil Jangra

## Translators

Expand Down
1 change: 1 addition & 0 deletions docs/releases/5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Thank you to Damilola for his work, and to Google for sponsoring this project.
* Implement a new design for chooser buttons with better accessibility (Thibaud Colas)
* Add [`AbstractImage.get_renditions()`](image_renditions_multiple) for efficient generation of multiple renditions (Andy Babic)
* Optimise queries in collection permission policies using cache on the user object (Sage Abdullah)
* Phone numbers entered via a link chooser will now have any spaces stripped out, ensuring a valid `href="tel:..."` attribute (Sahil Jangra)

### Bug fixes

Expand Down
12 changes: 12 additions & 0 deletions wagtail/admin/tests/test_page_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,18 @@ def test_notice_changes_to_link_text(self):
# link text has changed, so tell the caller to use it
self.assertIs(result["prefer_this_title_as_link_text"], True)

def test_phone_number_has_spaces(self):
response = self.post(
{
"phone-link-chooser-phone_number": "+1 234 567 890",
"phone-link-chooser-link_text": "call",
}
)
result = json.loads(response.content.decode())["result"]
self.assertEqual(result["url"], "tel:+1234567890")
self.assertEqual(result["title"], "call")
self.assertIs(result["prefer_this_title_as_link_text"], True)


class TestCanChoosePage(WagtailTestUtils, TestCase):
fixtures = ["test.json"]
Expand Down
1 change: 1 addition & 0 deletions wagtail/admin/views/chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,5 @@ class PhoneLinkView(BaseLinkFormView):
link_url_field_name = "phone_number"

def get_url_from_field_value(self, value):
value = re.sub(r"\s", "", value)
return "tel:" + value

0 comments on commit c7039ed

Please sign in to comment.