From b3d5fa20975b6073fc0ccb9e4c75d4e43a921c14 Mon Sep 17 00:00:00 2001 From: Gerry Nelson <45608078+gerrynelson63@users.noreply.github.com> Date: Mon, 12 Sep 2022 10:22:36 -0400 Subject: [PATCH] Bug/filenames closes #109 (#112) * update get_valid_filename * fix spacing * Update sharedfunctions.py Co-authored-by: cloud-user --- sharedfunctions.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sharedfunctions.py b/sharedfunctions.py index 3dec907..930173f 100755 --- a/sharedfunctions.py +++ b/sharedfunctions.py @@ -37,6 +37,7 @@ # 16Jul2021 Edited callrestapi to be able to update the header. (Issue #83) # 20Feb2022 Support patch # 28Feb2022 Added functionality to callrestapi optionally pass in etags, and to request they be returned, for API endpoints that use them +# 08Sep2022 Catch Unicode error in get_valid_filename and remove string function if it happens # # Copyright © 2018, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # @@ -709,8 +710,16 @@ def simplejsonresults(resultdata): def get_valid_filename(s): - s = str(s).strip().replace(' ', '_') - return re.sub(r'(?u)[^-\w.]', '', s) + + + #try original method, if it fails with encoding error remove string function + try: + s = str(s).strip().replace(' ', '_') + + except UnicodeEncodeError: + s = s.strip().replace(' ', '_') + + return re.sub(r'(?u)[^-\w.]', '', s) # getapplicationproperties # 20nov2020 initial development