Skip to content

Handle requests without _route safely in active_for_routes #45

Description

@javihgil

Problem

active_for_routes() assumes the current request has a _route attribute.

If a request exists but the route attribute is missing, the helper can behave in a fragile way because the value is used directly in preg_match().

Current evidence

  • src/Twig/Extension/ActiveForRoutesExtension.php reads $request->attributes->get('_route')
  • the value is then passed into preg_match() without an explicit guard for missing or non-string values

Expected behavior

The helper should return an empty string when the current request does not provide a valid route name.

Suggested work

  • guard the _route value before matching
  • treat missing or non-string route names as a non-match
  • add tests that cover requests without _route

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions