Problem/Motivation

Symfony allows parameters to be separated either by slash or by a dot. As per the Symfony documentation this is especially useful to match file extensions into the _format parameter.

rt.test.works:
  path: '/rt/works/{_format}'
  defaults:
    _controller: ...
    _format: "html"
  requirements:
    _access: 'TRUE'

rt.test.breaks:
  path: '/rt/breaks.{_format}'
  defaults:
    _controller: ...
    _format: "html"
  requirements:
    _access: 'TRUE'

This can then be used in any code with access to the request object to resolve a format or mime type.

Code supporting this can be found here:

Proposed resolution

Remaining tasks

User interface changes

API changes

Comments

znerol’s picture

Status: Active » Needs review
StatusFileSize
new1.86 KB

A desperately ugly first attempt.

Status: Needs review » Needs work

The last submitted patch, 1: 2409187-respect-extension-in-path-outline.diff, failed testing.

znerol’s picture

Status: Needs work » Needs review
StatusFileSize
new725 bytes
new1.87 KB
znerol’s picture

Issue tags: +SprintWeekend2015
dawehner’s picture

Issue tags: +WSCCI

Interesting

neclimdul’s picture

Issue summary: View changes

That's really cool. The documentation was a bit lacking on technical details so I dug into some code and updated the summary with what I found. Haven't looked too much into the patch but so far, big +1.

znerol’s picture

The current patch is not more than a hack in order to estimate the work needed to fix the Drupal specific extensions of the compiled route (pattern outline, fit and num parts). Symfony understands even more separators RouteCompiler::SEPARATORS. But it is probably not necessary/desirable to support them all in Drupal?

znerol’s picture

It seems to me that generating the pattern outline, fit and num parts would be much easier by just examining the tokens produced by the upstream route compiler. This would make Drupal automatically compatible to the whole Symfony route pattern syntax. Note however, that it would be necessary to adapt the outline candidate generator in RouteProvider also.

I've inlined all the code because other parts of Drupal seem to depend on the pulbic methods exposed by the Drupal RouteCompiler.

znerol’s picture

That is not as easy as it seems though. The Symfony route compiler generates a single token for a continuous path without any placeholders in between. E.g. /node/add/{node_type] only generates two tokens (num_parts = 2, fit = 2), while HEAD generates num_parts = 3, fit = 6.

Crell’s picture

The "Fit" algorithm was ported forward from Drupal 7 essentially unchanged, because it worked. I believe it's specific to the SQL implementation, though. I'm fine with expanding the definition of what we consider a valid path pattern, but we have to be mindful that it needs to be implementable in SQL, MongoDB, raw PHP, and whatever other implementations we want to support.

Status: Needs review » Needs work

The last submitted patch, 8: 2409187-respect-extension-in-path-outline-8.diff, failed testing.

znerol’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB

I believe it's specific to the SQL implementation, though.

That's not correct. The resulting SQL is very simple and portable to any decent database:

SELECT name, route FROM router WHERE pattern_outline IN (:patterns) ORDER BY fit DESC, name ASC

The pattern outline is essentially a secondary index. It is used to reduce the set of routes to be loaded prior to actually matching the incoming path against the route collection. Efficiency of this approach could be measured by tracking false positives, i.e. routes loaded from the db but later rejected by the regex.

That said, the obvious way to make the extension syntax work is simply to ignore file extensions altogether when generating the pattern outline and pattern outline candidates respectively. The attached patch implements this, no interdiff because this is yet another experiment.

Status: Needs review » Needs work
Crell’s picture

Or what if for outline purposes we treated the format as part of the pattern? Ie, replaced . with / before calculating the outline and fit?

And by SQL-specific, I mean non-SQL implementations may have something much better they can use. Eg, some SQL backends support regex matching in the query itself; that may or may not be faster on some engines. MongoDB probably has something similar although I'm not sure off hand. Someone was working on a Redis(!) backend for the Router, although how that even works I don't know... :-)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Are we sure we really want to support that?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

longwave’s picture

Version: 8.9.x-dev » 9.3.x-dev
Category: Bug report » Task
Issue tags: +Bug Smash Initiative

Found via the Bug Smash Initiative random issue triage.

There hasn't been any interest or movement on this for some years, and we don't claim to support everything Symfony does, so reclassifying as a task.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Just stumbled upon this in a client project, thought I was going nuts. Dug down into the router until I found the source of the issue. Then find someone has been down this route before 🥁

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.