9

If you attempt to create a module with a front name like hello-world in Magento 2, you'll get an error that looks like this.

Invalid XML in file /Users/alanstorm/Sites/magento-2-with-keys/magento2/app/code/Pulsestorm/HelloPestle/etc/frontend/routes.xml:
Element 'route', attribute 'id': [facet 'pattern'] The value 
'hello-world' is not accepted by the pattern '[A-Za-z0-9_]{3,}'.

It seems like Magento doesn't want URL front names that have anything other than a number, letter, or underscore in them. It also forces front names to have three or more characters.

The number, letter, and underscore limitation make sense since a route ID is used to create a layout handle and "special" characters there may cause a problem. However, the three character limit is confusing.

Does anyone know the reason for this?

2
  • Maybe this is because of XSD validations that are in place. Commented Jan 8, 2016 at 9:47
  • 2
    @Bhargav Yes, but why is the XSD configured that way? Commented Jan 8, 2016 at 19:17

3 Answers 3

4

The reason was to avoid messy declarations with too short identifiers (same as too short variable limitations in PHP code style analyzers).

It was applied to multiple field types. Route front name has this limitation by mistake. It will be fixed

0

change hello-world as hello_world

Valid characters are alphabet, numeric and _

1
  • This doesn't seem to answer the question? Commented Nov 16, 2016 at 17:11
-2

Yes, it's in .xsd (routerIdType, routeIdType, moduleNameType, beforeAfterType, routeFrontNameType). Reason is unknown.

https://github.com/magento/magento2/blob/077584c99ebb8007cad176c3b9a0144a05c259cd/lib/internal/Magento/Framework/App/etc/routes.xsd

https://github.com/magento/magento2/blob/077584c99ebb8007cad176c3b9a0144a05c259cd/lib/internal/Magento/Framework/App/etc/routes_merged.xsd

1
  • 2
    I'm not interested in the technical details of how the limitation was implemented, I want to know why it's there in the first place. Commented Jan 8, 2016 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.