Skip to content

Commit

Permalink
fix: make tests pass
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mbideau committed May 1, 2023
1 parent 32cccf2 commit e8fefc2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/cases/From 2.1 to 3.0 without coma escaping/options
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--do-not-force-escape-comas
--do-not-force-escape-commas
12 changes: 9 additions & 3 deletions vcardlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions vcardtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e8fefc2

Please sign in to comment.