Commit b89336a3f2a1d978a182f17a34d2f4317d2dd270

Authored by Christian Herdtweck
1 parent cb436a2f

msodde: Fix UnicodeError

Some debug-logging did not take into account that data added to
output could be non-ascii.
Showing 1 changed file with 9 additions and 9 deletions
oletools/msodde.py
@@ -363,7 +363,7 @@ def process_doc_field(data): @@ -363,7 +363,7 @@ def process_doc_field(data):
363 """ check if field instructions start with DDE 363 """ check if field instructions start with DDE
364 364
365 expects unicode input, returns unicode output (empty if not dde) """ 365 expects unicode input, returns unicode output (empty if not dde) """
366 - logger.debug('processing field {0}'.format(data)) 366 + logger.debug(u'processing field {0}'.format(data))
367 367
368 if data.lstrip().lower().startswith(u'dde'): 368 if data.lstrip().lower().startswith(u'dde'):
369 return data 369 return data
@@ -626,7 +626,7 @@ def field_is_blacklisted(contents): @@ -626,7 +626,7 @@ def field_is_blacklisted(contents):
626 index = FIELD_BLACKLIST_CMDS.index(words[0].lower()) 626 index = FIELD_BLACKLIST_CMDS.index(words[0].lower())
627 except ValueError: # first word is no blacklisted command 627 except ValueError: # first word is no blacklisted command
628 return False 628 return False
629 - logger.debug('trying to match "{0}" to blacklist command {1}' 629 + logger.debug(u'trying to match "{0}" to blacklist command {1}'
630 .format(contents, FIELD_BLACKLIST[index])) 630 .format(contents, FIELD_BLACKLIST[index]))
631 _, nargs_required, nargs_optional, sw_with_arg, sw_solo, sw_format \ 631 _, nargs_required, nargs_optional, sw_with_arg, sw_solo, sw_format \
632 = FIELD_BLACKLIST[index] 632 = FIELD_BLACKLIST[index]
@@ -638,12 +638,12 @@ def field_is_blacklisted(contents): @@ -638,12 +638,12 @@ def field_is_blacklisted(contents):
638 break 638 break
639 nargs += 1 639 nargs += 1
640 if nargs < nargs_required: 640 if nargs < nargs_required:
641 - logger.debug('too few args: found {0}, but need at least {1} in "{2}"' 641 + logger.debug(u'too few args: found {0}, but need at least {1} in "{2}"'
642 .format(nargs, nargs_required, contents)) 642 .format(nargs, nargs_required, contents))
643 return False 643 return False
644 if nargs > nargs_required + nargs_optional: 644 if nargs > nargs_required + nargs_optional:
645 - logger.debug('too many args: found {0}, but need at most {1}+{2} in '  
646 - '"{3}"' 645 + logger.debug(u'too many args: found {0}, but need at most {1}+{2} in '
  646 + u'"{3}"'
647 .format(nargs, nargs_required, nargs_optional, contents)) 647 .format(nargs, nargs_required, nargs_optional, contents))
648 return False 648 return False
649 649
@@ -653,14 +653,14 @@ def field_is_blacklisted(contents): @@ -653,14 +653,14 @@ def field_is_blacklisted(contents):
653 for word in words[1+nargs:]: 653 for word in words[1+nargs:]:
654 if expect_arg: # this is an argument for the last switch 654 if expect_arg: # this is an argument for the last switch
655 if arg_choices and (word not in arg_choices): 655 if arg_choices and (word not in arg_choices):
656 - logger.debug('Found invalid switch argument "{0}" in "{1}"' 656 + logger.debug(u'Found invalid switch argument "{0}" in "{1}"'
657 .format(word, contents)) 657 .format(word, contents))
658 return False 658 return False
659 expect_arg = False 659 expect_arg = False
660 arg_choices = [] # in general, do not enforce choices 660 arg_choices = [] # in general, do not enforce choices
661 continue # "no further questions, your honor" 661 continue # "no further questions, your honor"
662 elif not FIELD_SWITCH_REGEX.match(word): 662 elif not FIELD_SWITCH_REGEX.match(word):
663 - logger.debug('expected switch, found "{0}" in "{1}"' 663 + logger.debug(u'expected switch, found "{0}" in "{1}"'
664 .format(word, contents)) 664 .format(word, contents))
665 return False 665 return False
666 # we want a switch and we got a valid one 666 # we want a switch and we got a valid one
@@ -682,7 +682,7 @@ def field_is_blacklisted(contents): @@ -682,7 +682,7 @@ def field_is_blacklisted(contents):
682 if 'numeric' in sw_format: 682 if 'numeric' in sw_format:
683 arg_choices = [] # too many choices to list them here 683 arg_choices = [] # too many choices to list them here
684 else: 684 else:
685 - logger.debug('unexpected switch {0} in "{1}"' 685 + logger.debug(u'unexpected switch {0} in "{1}"'
686 .format(switch, contents)) 686 .format(switch, contents))
687 return False 687 return False
688 688
@@ -900,7 +900,7 @@ def process_excel_xml(filepath): @@ -900,7 +900,7 @@ def process_excel_xml(filepath):
900 break 900 break
901 if formula is None: 901 if formula is None:
902 continue 902 continue
903 - logger.debug('found cell with formula {0}'.format(formula)) 903 + logger.debug(u'found cell with formula {0}'.format(formula))
904 match = re.match(XML_DDE_FORMAT, formula) 904 match = re.match(XML_DDE_FORMAT, formula)
905 if match: 905 if match:
906 dde_links.append(u' '.join(match.groups()[:2])) 906 dde_links.append(u' '.join(match.groups()[:2]))