From e8fefc254d70e447dedc6025e3b7aae3be1b03da Mon Sep 17 00:00:00 2001 From: Michael Bideau Date: Mon, 1 May 2023 14:27:01 +0200 Subject: [PATCH] fix: make tests pass - option OPTION_DOT_NOT_FORCE_ESCAPE_COMAS wasn't renamed in the lib to OPTION_DO_NOT_FORCE_ESCAPE_COMMAS - function 'sanitise_name' was reoving space from filename - wrong usage of `mk_vcard_fnm(d_path, the_vcard_ext)` was replacing '/' in path making the card always stored in the current directory rather than the specified one --- .../From 2.1 to 3.0 without coma escaping/options | 2 +- vcardlib.py | 12 +++++++++--- vcardtools.py | 5 ++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/cases/From 2.1 to 3.0 without coma escaping/options b/test/cases/From 2.1 to 3.0 without coma escaping/options index 84ead8a..2c42358 100644 --- a/test/cases/From 2.1 to 3.0 without coma escaping/options +++ b/test/cases/From 2.1 to 3.0 without coma escaping/options @@ -1 +1 @@ ---do-not-force-escape-comas +--do-not-force-escape-commas diff --git a/vcardlib.py b/vcardlib.py index 540024b..5a71233 100644 --- a/vcardlib.py +++ b/vcardlib.py @@ -62,7 +62,7 @@ OPTION_MATCH_APPROX_RATIO = 100 OPTION_UPDATE_GROUP_KEY = True OPTION_FRENCH_TWEAKS = False -OPTION_DOT_NOT_FORCE_ESCAPE_COMAS = False +OPTION_DO_NOT_FORCE_ESCAPE_COMMAS = False SINGLE_INSTANCE_PROPERTIES = {'prodid', 'rev', 'uid'} @@ -965,8 +965,11 @@ def fix_and_convert_to_v3(file_path): # pylint: disable=too-many-statements,too logging.debug("\tmultiline value hack (joining this line with the previous)") if last_line.replace('\n', '')[-1:] == '=': last_line = re.sub('=$', '', last_line.replace('\n', '')) + '\n' - if not OPTION_DOT_NOT_FORCE_ESCAPE_COMAS: + if not OPTION_DO_NOT_FORCE_ESCAPE_COMMAS: + logging.debug("\tescaping commas...") + logging.debug("\t\tbefore: %s", line) line = re.sub('([^\\\\]|^),', '\\1\\,', line) + logging.debug("\t\tafter : %s", line) last_line = last_line.replace('\n', '') + line.strip() + '\n' logging.debug("\tconcatened: '%s'", line.strip()) logging.debug("\t") @@ -996,8 +999,11 @@ def fix_and_convert_to_v3(file_path): # pylint: disable=too-many-statements,too rest_part = re.sub(r'^([^:]+):', '', new_line) logging.debug("\trest part: '%s'", rest_part) - if not OPTION_DOT_NOT_FORCE_ESCAPE_COMAS: + if not OPTION_DO_NOT_FORCE_ESCAPE_COMMAS: + logging.debug("\tescaping commas...") + logging.debug("\t\tbefore: %s", rest_part) rest_part = re.sub('([^\\\\]|^),', '\\1\\,', rest_part) + logging.debug("\t\tafter : %s", rest_part) new_line = key_part + ':' + rest_part logging.debug("\tbuilt new line: %s", new_line) diff --git a/vcardtools.py b/vcardtools.py index 5de759f..e4bce36 100644 --- a/vcardtools.py +++ b/vcardtools.py @@ -122,7 +122,7 @@ def sanitise_name(a_name: str) -> str: and replacing them with something safe (in this case, an underscore) """ NEW_REPLACEMENT_CHAR = '_' - FROM_CHARACTERS = ' .\\/"\'!@#?$%^&*|()[]{};:<>' + FROM_CHARACTERS = '.\\/"\'!@#?$%^&*|()[]{};:<>' for old_char in FROM_CHARACTERS: a_name = a_name.replace(old_char, NEW_REPLACEMENT_CHAR) @@ -270,8 +270,7 @@ def main(): # pylint: disable=too-many-statements,too-many-branches # save the remaining attributes to the merged vCard vcard_merge = build_vcard(attributes) # write to the file - write_vcard_to_file(vcard_merge, mk_vcard_fnm(d_path, the_vcard_ext)) - # write_vcard_to_file(vcard_merge, d_path + '.vcard') + write_vcard_to_file(vcard_merge, d_path + the_vcard_ext) # group else: