Commit 9012a9e2 authored by Baptiste Mispelon's avatar Baptiste Mispelon Committed by Claude Paroz
Browse files

Fixed #20422 -- Applied makemessage's --ignore patterns to full path

Fix makemessage's --ignore patterns being applied to the full path
instead of the file name. Thanks to nnseva for the report and the
original patch.
parent 1d3d0407
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -309,10 +309,9 @@ class Command(NoArgsCommand):
            """
            Check if the given path should be ignored or not.
            """
            for pattern in ignore_patterns:
                if fnmatch.fnmatchcase(path, pattern):
                    return True
            return False
            filename = os.path.basename(path)
            ignore = lambda pattern: fnmatch.fnmatchcase(filename, pattern)
            return any(ignore(pattern) for pattern in ignore_patterns)

        dir_suffix = '%s*' % os.sep
        norm_patterns = [p[:-len(dir_suffix)] if p.endswith(dir_suffix) else p for p in self.ignore_patterns]
+7 −2
Original line number Diff line number Diff line
@@ -279,17 +279,22 @@ class IgnoredExtractorTests(ExtractorTests):

    def test_ignore_option(self):
        os.chdir(self.test_dir)
        pattern1 = os.path.join('ignore_dir', '*')
        ignore_patterns = [
            os.path.join('ignore_dir', '*'),
            'xxx_*',
        ]
        stdout = StringIO()
        management.call_command('makemessages', locale=LOCALE, verbosity=2,
            ignore_patterns=[pattern1], stdout=stdout)
            ignore_patterns=ignore_patterns, stdout=stdout)
        data = stdout.getvalue()
        self.assertTrue("ignoring directory ignore_dir" in data)
        self.assertTrue("ignoring file xxx_ignored.html" in data)
        self.assertTrue(os.path.exists(self.PO_FILE))
        with open(self.PO_FILE, 'r') as fp:
            po_contents = fp.read()
            self.assertMsgId('This literal should be included.', po_contents)
            self.assertNotMsgId('This should be ignored.', po_contents)
            self.assertNotMsgId('This should be ignored too.', po_contents)


class SymlinkExtractorTests(ExtractorTests):
+2 −0
Original line number Diff line number Diff line
{% load i18n %}
{% trans "This should be ignored too." %}