From 629872ad4bafc322ebc49fbb5823527e770f65fe Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Wed, 20 Mar 2019 15:25:41 -0700 Subject: [PATCH] :bug: Handle unicode in ini_file_parser.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This bug was trigged only when Unicode was on the RHS e.g. ``` foo=bår ``` --- detect_secrets/plugins/common/ini_file_parser.py | 7 +++++-- test_data/config.ini | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/detect_secrets/plugins/common/ini_file_parser.py b/detect_secrets/plugins/common/ini_file_parser.py index c7918f3fe..e4b433cff 100644 --- a/detect_secrets/plugins/common/ini_file_parser.py +++ b/detect_secrets/plugins/common/ini_file_parser.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import configparser import re @@ -20,7 +22,8 @@ def __init__(self, file, add_header=False, exclude_lines_regex=None): try: # python2.7 compatible self.parser.optionxform = unicode - except NameError: + except NameError: # pragma: no cover + # python3 compatible self.parser.optionxform = str self.exclude_lines_regex = exclude_lines_regex @@ -34,7 +37,7 @@ def __init__(self, file, add_header=False, exclude_lines_regex=None): try: # python2.7 compatible self.parser.read_string(unicode(content)) - except NameError: + except NameError: # pragma: no cover # python3 compatible self.parser.read_string(content) diff --git a/test_data/config.ini b/test_data/config.ini index 97f5e14b4..cd2dc9f23 100644 --- a/test_data/config.ini +++ b/test_data/config.ini @@ -24,3 +24,6 @@ keyB = 456789123 keyC = password = 12345678901234 # pragma: whitelist secret + +# unicode +foo=bår