Problem/Motivation

The function fnmatch is not available in every PHP build. Related core issue: #2620576: fnmatch() is not available on all environments (i.e QNAP QTS).

Running Upgrade Status on Configuration Distribution produces the following:

File name Line Error
web/modules/contrib/config_distro/modules/config_distro_ignore/src/Plugin/ConfigFilter/DistroIgnoreFilter.php 138 Calls to function fnmatch should not exist.
web/modules/contrib/config_distro/modules/config_distro_ignore/src/Plugin/ConfigFilter/DistroIgnoreFilter.php 158 Calls to function fnmatch should not exist.

Proposed resolution

Replace fnmatch() with preg_match().

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

nedjo created an issue. See original summary.

a.dmitriiev’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB

Please review attached patch.

nedjo’s picture

@a.dmitriiev

Thanks for the patch!

I don't follow it well enough to understand what it's doing or why. The core commit for #2620576: fnmatch() is not available on all environments (i.e QNAP QTS) was mostly single-line substitutions. Can you explain a bit why we need to do more here?

a.dmitriiev’s picture

I think my change covers all the possible fnmatch cases, maybe it is overdoing ofcourse. Let's stick to the core approach. I will prepare a new patch.

a.dmitriiev’s picture

Assigned: Unassigned » a.dmitriiev
a.dmitriiev’s picture

Here is the new patch attached, following core approach.

joegraduate’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
joegraduate’s picture

tadean’s picture

Thank you for these great patches @a.dmitriiev !

I tested both of these patches out with the config_distro_ignore functionality. In my testing it appears that the patch in #3144145-6: Consider replacing fnmatch usage has an issue where any ignore rule will match any config name (e.g. foo will match node.type.my_content_type). The original patch in #3144145-2: Consider replacing fnmatch usage seemed to work in almost all cases but has a minor issue where a partial match now matches a complete config name (e.g. content matches node.type.my_content_type because the generated regex pattern was missing the ^$

I have updated the patch in #3144145-2: Consider replacing fnmatch usage to fix the substring issue, use preg_quote, and for coding standards. I have removed the case insensitivity flag because fnmatch() wasn't originally being used with FNM_CASEFOLD. I think in some cases (windows platforms, maybe?) the original implementation using fnmatch() might have been case insensitive in some places and not others.

Most of the fnmatch() replacements in Drupal have not been a complete reimplementation of the shell-style patterns as regex, but this patch retains the wildcard functionality on * and ?, which I think is useful for the config_distro_ignore use case.

joegraduate’s picture

Patch in #9 looks good to me. Thanks @tadean!

Discussed this offline with @tadean and we are in agreement that it would be good to merge this ahead of an alpha release with D10 compatibility and create a follow-up issue that adds automated test coverage for this functionality before creating a beta release.

trackleft2’s picture

Status: Needs review » Reviewed & tested by the community

Tested with many patterns using the test module after changing config within the core.entity_form_display.node.sample_content_type.default.yml file including:

core.entity_form_display.node.sample_content_type.*
core.entity_form_display.node.sample_content_typ?.???????

  • tadean authored 2c4e730d on 2.0.x
    Issue #3144145 by a.dmitriiev, tadean, nedjo, joegraduate, trackleft2:...
joegraduate’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 2.0.x. Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.