From 6cadbdf3541c92616c2788f334b61f65c5006f55 Mon Sep 17 00:00:00 2001 From: Kevin Yap Date: Wed, 12 Oct 2016 23:22:33 -0700 Subject: [PATCH] Fix extension-matching bug in generators.py Addresses #1946. --- pelican/generators.py | 8 +++++--- pelican/tests/content/bad_extension.mmd | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 pelican/tests/content/bad_extension.mmd diff --git a/pelican/generators.py b/pelican/generators.py index 2107e338..af3e3513 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -100,8 +100,8 @@ class Generator(object): """Inclusion logic for .get_files(), returns True/False :param path: the path which might be including - :param extensions: the list of allowed extensions (if False, all - extensions are allowed) + :param extensions: the list of allowed extensions, or False if all + extensions are allowed """ if extensions is None: extensions = tuple(self.readers.extensions) @@ -112,8 +112,10 @@ class Generator(object): if any(fnmatch.fnmatch(basename, ignore) for ignore in ignores): return False - if extensions is False or basename.endswith(extensions): + ext = os.path.splitext(basename)[1][1:] + if extensions is False or ext in extensions: return True + return False def get_files(self, paths, exclude=[], extensions=None): diff --git a/pelican/tests/content/bad_extension.mmd b/pelican/tests/content/bad_extension.mmd new file mode 100644 index 00000000..d282a749 --- /dev/null +++ b/pelican/tests/content/bad_extension.mmd @@ -0,0 +1,3 @@ +Title: Bad Extension + +This file shouldn't be included because its file extension is `.mmd`.