From d9312f28ab67e8e0d62d5fa699c48f918fcab1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Gonz=C3=A1lez=20Alonso?= Date: Mon, 25 Nov 2024 16:27:15 +0100 Subject: [PATCH] fix: remove accents from file names (#406) --- CHANGELOG.rst | 2 ++ toolium/test/utils/test_path_utils.py | 1 + toolium/utils/path_utils.py | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b00f317c..7a3cb9bd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,11 +5,13 @@ v3.2.1 ------ *Release date: In development* + - Allow negative indexes for list elements in context searches. Example: [CONTEXT:element.-1] - Add support for JSON strings to the `DICT` and `LIST`` replacement. Example: [DICT:{"key": true}], [LIST:[null]] - Add `REPLACE` replacement, to replace a substring with another. Example: [REPLACE:[CONTEXT:some_url]::https::http] - Add `TITLE` replacement, to apply Python's title() function. Example: [TITLE:the title] - Add `ROUND` replacement, float number to a string with the indicated number of decimals. Example: [ROUND:3.3333::2] +- Remove accents from generated file names to avoid errors in some filesystems v3.2.0 ------ diff --git a/toolium/test/utils/test_path_utils.py b/toolium/test/utils/test_path_utils.py index b3a8c820..b8149fa5 100644 --- a/toolium/test/utils/test_path_utils.py +++ b/toolium/test/utils/test_path_utils.py @@ -30,6 +30,7 @@ ('successful login -- @1.1 john.doe', 'successful_login_1_1_john_doe'), ('successful login -- @1.2 Mark options: {Length=10 Mark=mark File=file_name.jpg}', 'successful_login_1_2_Mark_options___Length_10_Mark_mark_File_file_name_jpg'), + ('successful login -- @1.3 acción', 'successful_login_1_3_accion'), ) diff --git a/toolium/utils/path_utils.py b/toolium/utils/path_utils.py index a6af05bb..010f3015 100644 --- a/toolium/utils/path_utils.py +++ b/toolium/utils/path_utils.py @@ -16,9 +16,10 @@ limitations under the License. """ -from os import makedirs import errno import re +import unicodedata +from os import makedirs FILENAME_MAX_LENGTH = 100 @@ -34,6 +35,9 @@ def get_valid_filename(s, max_length=FILENAME_MAX_LENGTH): """ s = str(s).strip().replace(' -- @', '_') s = re.sub(r'(?u)[^-\w]', '_', s).strip('_') + # Remove accents to avoid errors in some filesystems + nfkd_form = unicodedata.normalize('NFKD', s) + s = ''.join([c for c in nfkd_form if not unicodedata.combining(c)]) return s[:max_length]