This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cykerway
Recipients cykerway, josh.r, serhiy.storchaka, xtreak
Date 2018-11-26.23:30:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1543275016.33.0.788709270274.issue35314@psf.upfronthosting.co.za>
In-reply-to
Content
Thank you for confirmation. Knowing it is not fully POSIX-compliant helps with understanding.

I'm asking this because I had interoperability issues writing python scripts providing shell-like utilities for filename expansion and the result may surprise users. The glibc fnmatch provides a flag named `FNM_PATHNAME`, which is missing in the python fnmatch implementation. So I think there is currently no way to tell the python library if we are matching a filename or not.

All right so this is not a bug, but probably a good enhancement.

## TLDR

This is what POSIX says **for filename expansion**, in section 2.13.3:

<http://pubs.opengroup.org/onlinepubs/9699919799.2008edition/>

>   when pattern matching notation is used for filename expansion:
>
>   1.  The <slash> character in a pathname shall be explicitly matched by using one or more <slash> characters in the pattern; it shall neither be matched by the <asterisk> or <question-mark> special characters nor by a bracket expression. <slash> characters in the pattern shall be identified before bracket expressions; thus, a <slash> cannot be included in a pattern bracket expression used for filename expansion. If a <slash> character is found following an unescaped <left-square-bracket> character before a corresponding <right-square-bracket> is found, the open bracket shall be treated as an ordinary character. For example, the pattern "a[b/c]d" does not match such pathnames as abd or a/d. It only matches a pathname of literally a[b/c]d.

Currently python fnmatch.fnmatch gives:

    >>> fnmatch('abd', 'a[b/c]d')
    True
    >>> fnmatch('a/d', 'a[b/c]d')
    True
    >>> fnmatch('a[b/c]d', 'a[b/c]d')
    False

Ideally we can call `fnmatch('a/d', 'a[b/c]d', fnm_pathname=True)` to correct the behavior.
History
Date User Action Args
2018-11-26 23:30:16cykerwaysetrecipients: + cykerway, serhiy.storchaka, josh.r, xtreak
2018-11-26 23:30:16cykerwaysetmessageid: <1543275016.33.0.788709270274.issue35314@psf.upfronthosting.co.za>
2018-11-26 23:30:16cykerwaylinkissue35314 messages
2018-11-26 23:30:16cykerwaycreate