Thanks to visit codestin.com
Credit goes to github.com

Skip to content

All resource exclude paths are completely ignored #54212

Closed
@Bilge

Description

@Bilge

Symfony version(s) affected

6.4.3

Description

Given the example in the documentation:

# config/routes/attributes.yaml
controllers:
    resource: '../../src/Controller/'
    type: attribute
    # this is added to the beginning of all imported route URLs
    prefix: '/blog'
    # this is added to the beginning of all imported route names
    name_prefix: 'blog_'
    # these requirements are added to all imported routes
    requirements:
        _locale: 'en|es|fr'

    # An imported route with an empty URL will become "/blog/"
    # Uncomment this option to make that URL "/blog" instead
    # trailing_slash_on_root: false

    # you can optionally exclude some files/subdirectories when loading attributes
    # (the value must be a string or an array of PHP glob patterns)
    # exclude: '../../src/Controller/{Debug*Controller.php}'

If one were to actually uncomment the exclude line, it would have no effect whatsoever.

How to reproduce

Uncomment the exclude line.

# config/routes/attributes.yaml
controllers:
    resource: '../../src/Controller/'
    type: attribute
    # this is added to the beginning of all imported route URLs
    prefix: '/blog'
    # this is added to the beginning of all imported route names
    name_prefix: 'blog_'
    # these requirements are added to all imported routes
    requirements:
        _locale: 'en|es|fr'

    # An imported route with an empty URL will become "/blog/"
    # Uncomment this option to make that URL "/blog" instead
    # trailing_slash_on_root: false

    # you can optionally exclude some files/subdirectories when loading attributes
    # (the value must be a string or an array of PHP glob patterns)
    exclude: '../../src/Controller/{Debug*Controller.php}'

Possible Solution

This appears to be because of this line, and more specifically, this condition:

\strlen($resource) !== ($i = strcspn($resource, '*?{['))

This seems to imply that if the resource itself is not a glob then all exclusion processing will be dropped. This is not documented anywhere nor does it make any particular sense to me.

Additional Context

Relates to #39588.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions