From 2b71cce88b6e4c3fd2576cfe2d5b935a553afed6 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Tue, 9 Mar 2021 15:26:27 -0500 Subject: [PATCH] (core) Fix CONCAT function that was breaking on presence of non-ascii characters Summary: This was the only occurrence of the unicode() function that I could find. Test Plan: Added a doctest case. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2750 --- sandbox/grist/functions/text.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/sandbox/grist/functions/text.py b/sandbox/grist/functions/text.py index cfec1200..83edd13a 100644 --- a/sandbox/grist/functions/text.py +++ b/sandbox/grist/functions/text.py @@ -56,7 +56,7 @@ def CODE(string): def CONCATENATE(string, *more_strings): """ Joins together any number of text strings into one string. Also available under the name - `CONCAT`. Same as the Python expression `"".join(array_of_strings)`. + `CONCAT`. Similar to the Python expression `"".join(array_of_strings)`. >>> CONCATENATE("Stream population for ", "trout", " ", "species", " is ", 32, "/mile.") u'Stream population for trout species is 32/mile.' @@ -64,13 +64,32 @@ def CONCATENATE(string, *more_strings): u'In 4 days it is 2016-01-01' >>> CONCATENATE("abc") u'abc' + >>> CONCATENATE(0, "abc") + u'0abc' + >>> CONCATENATE(2, " crème ", "brûlée".decode('utf8')) == "2 crème brûlée".decode('utf8') + True + """ + return u''.join(val if isinstance(val, unicode) else str(val).decode('utf8') + for val in (string,) + more_strings) + + +def CONCAT(string, *more_strings): + """ + Joins together any number of text strings into one string. Also available under the name + `CONCATENATE`. Similar to the Python expression `"".join(array_of_strings)`. + + >>> CONCAT("Stream population for ", "trout", " ", "species", " is ", 32, "/mile.") + u'Stream population for trout species is 32/mile.' + >>> CONCAT("In ", 4, " days it is ", datetime.date(2016,1,1)) + u'In 4 days it is 2016-01-01' + >>> CONCAT("abc") + u'abc' >>> CONCAT(0, "abc") u'0abc' + >>> CONCAT(2, " crème ", "brûlée".decode('utf8')) == "2 crème brûlée".decode('utf8') + True """ - return u''.join(unicode(val) for val in (string,) + more_strings) - - -CONCAT = CONCATENATE + return CONCATENATE(string, *more_strings) def DOLLAR(number, decimals=2):