Author kleshni
Recipients kleshni
Date 2020-05-03.09:37:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1588498627.36.0.0280402477391.issue40480@roundup.psfhosted.org>
In-reply-to
Content
Hello. The following code hangs:

import fnmatch
fnmatch.fnmatchcase("a" * 32, "*" * 16 + "b")

Measurements show that its execution time rises exponentially with the number of asterisks. Bash and SQLite 3 process this glob instantly.

This is because "fnmatchcase" generates a regular expression with repeated dots:

(?s:.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*b)\\Z

It's equivalent to:

(?s:.*b)\\Z

But works in exponential time. So the solution is to replace multiple asterisks with a single one, so the latter regexp is generated instead.
History
Date User Action Args
2020-05-03 09:37:07kleshnisetrecipients: + kleshni
2020-05-03 09:37:07kleshnisetmessageid: <1588498627.36.0.0280402477391.issue40480@roundup.psfhosted.org>
2020-05-03 09:37:07kleshnilinkissue40480 messages
2020-05-03 09:37:07kleshnicreate