[diffoscope] 02/02: Fix bug introduced in commit 36d1c964 that only worked "accidentally"
Ximin Luo
infinity0 at debian.org
Fri Jan 27 16:07:59 CET 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit a28272fe0e1f55ce5fe87bf829b8bbc7134467ab
Author: Ximin Luo <infinity0 at debian.org>
Date: Fri Jan 27 16:07:50 2017 +0100
Fix bug introduced in commit 36d1c964 that only worked "accidentally"
The previous behaviour (before the commit) returns False if neither regexes are
defined. It is not possible to reduce this to a simple boolean expression; one
needs to explicitly check for the corner-case "neither are defined". The
behaviour in the other cases was correct (both before and after the commit),
however the use of the "match-all" regexp makes it hard to express the corner
case. So, rewrite the whole thing.
---
diffoscope/comparators/utils/file.py | 4 ++--
diffoscope/comparators/utils/specialize.py | 7 +++++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index 8fa6e13..55d4f74 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -40,8 +40,8 @@ logger = logging.getLogger(__name__)
class File(object, metaclass=abc.ABCMeta):
- RE_FILE_TYPE = re.compile(r'.^')
- RE_FILE_EXTENSION = re.compile(r'.^')
+ RE_FILE_TYPE = None
+ RE_FILE_EXTENSION = None
if hasattr(magic, 'open'): # use Magic-file-extensions from file
@classmethod
diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index 28e6cbb..ecb3101 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -38,8 +38,11 @@ def specialize(file):
with profile('recognizes', file):
flag = cls.recognizes(file)
else:
- flag = cls.RE_FILE_TYPE.search(file.magic_file_type) and \
- cls.RE_FILE_EXTENSION.search(file.name)
+ re_tests = [(cls.RE_FILE_TYPE, file.magic_file_type),
+ (cls.RE_FILE_EXTENSION, file.name)]
+ re_tests = filter(lambda pair: pair[0], re_tests)
+ if re_tests: # if neither are defined, it's *not* a match
+ flag = all(bool(pair[0].search(pair[1])) for pair in re_tests)
if not flag:
continue
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list