Handle binary files when scanning metadata in python 3 (#53773)

This commit is contained in:
Jordan Borean 2019-03-14 10:00:30 +10:00 committed by GitHub
parent 7f0e09aa31
commit c2466c545b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -394,8 +394,12 @@ def analyze_integration_target_dependencies(integration_targets):
for meta_path in meta_paths:
if os.path.exists(meta_path):
with open(meta_path, 'r') as meta_fd:
meta_lines = meta_fd.read().splitlines()
with open(meta_path, 'rb') as meta_fd:
# try and decode the file as a utf-8 string, skip if it contains invalid chars (binary file)
try:
meta_lines = meta_fd.read().decode('utf-8').splitlines()
except UnicodeDecodeError:
continue
for meta_line in meta_lines:
if re.search(r'^ *#.*$', meta_line):