Skip to content

Commit

Permalink
(core) Throwing error in PHONE_FORMAT when value is not a string
Browse files Browse the repository at this point in the history
Summary:
Adding type check in the PHONE_FORMAT function. Default
conversion to string doesn't work well for floats.

Test Plan: Updated

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3701
  • Loading branch information
berhalak committed Nov 14, 2022
1 parent 5c67e12 commit 044d7a1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sandbox/grist/functions/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,19 @@ def PHONE_FORMAT(value, country=None, format=None): # pylint: disable=redefined
u'tel:+33-2-34-56-78-90'
>>> PHONE_FORMAT("tel:+1-234-567-8901", country="US", format="*")
u'+12345678901'
>>> PHONE_FORMAT(33234567890)
Traceback (most recent call last):
...
TypeError: Phone number must be a text value. \
If formatting a value from a Numeric column, convert that column to Text first.
"""
if not value:
return value

if not isinstance(value, six.string_types):
raise TypeError("Phone number must be a text value. " +
"If formatting a value from a Numeric column, convert that column to Text first.")

if format is None and country in output_formats:
format = country
country = None
Expand Down

0 comments on commit 044d7a1

Please sign in to comment.