I'm currently porting the force_password_change module to D8. I found a bug with the following code:

force_password_change.admin:
  path: "/admin/config/people/force_password_change"
  defaults:
    _controller: "Drupal\force_password_change\Controller\ForcePasswordChangeController::adminPage"

I was getting the following error:

ReflectionException: Class \Drupal
orce_password_change\Controller\ForcePasswordChangeController does not exist in /Users/jay/websites/d8/core/lib/Drupal/Core/Entity/EntityResolverManager.php:123

Note the line break after Drupal, and before orce_password_change.

The system is treating the backslash-f as a linebreak when inside quotes.

Comments

Jaypan created an issue. See original summary.

cilefen’s picture

cspitzlay’s picture

No, I do not think the two issues are related.

#2792877: Symfony YAML parser fails on some strings when running PHP 7 is about an exceeded stack limit in the pcre jit implementation of PHP7.
This issue (#2838533: *.routing.yml - using \f (backslash f) inside quotes in for _controller results in an error) is about backslash-f being erroneously decoded into a form feed character if I am not mistaken (see https://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/backslash_co... ).

cilefen’s picture

Fair enough - you definitely did more reading than I. But given that, I feel this is miscategorized in the routing system. Ostensibly, it could happen in any YAML file. Is that correct?

cilefen’s picture

So this seems fundamental to YAML itself and not a Drupal bug.

cilefen’s picture

Category: Bug report » Support request
Status: Active » Fixed

You must single-quote or escape backslashes:

force_password_change.admin: 
  defaults: 
    _controller: "Drupal\\force_password_change\\Controller\\ForcePasswordChangeController::adminPage"
  path: /admin/config/people/force_password_change
cspitzlay’s picture

Yes, I have just come to the same conclusion.

I think it would also work with the original string if single quotes were used:
'Drupal\force_password_change\Controller\ForcePasswordChangeController::adminPage'

edit: Oops, that's what you already stated. :)

cilefen’s picture

Yes, and I should have realized the solution sooner, but I had just seen updates on #2792877: Symfony YAML parser fails on some strings when running PHP 7 and made wrong assumptions.

jaypan’s picture

Thanks guys. I added a note to one of the documentation pages mentioning to use single quotes instead of double quotes: https://www.drupal.org/docs/8/api/routing-system/introductory-drupal-8-r...

Status: Fixed » Closed (fixed)

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