【问题标题】:How to allow all special characters in a Route (Symfony2)如何允许路由中的所有特殊字符(Symfony2)
【发布时间】:2016-02-29 22:00:30
【问题描述】:

如何在路由路径中允许所有特殊字符:a-z A-Z 和 ?.!:/_()'`?我试过这个,但它根本不起作用。因为我想做一个错误报告 Action 发送一封包含当前错误描述的电子邮件。

bugReport:
path:     /bugReport/{eStatusCode}/{eMessage}
defaults: { _controller: utilisateurBundle:ExceptionReport:bugReport }    
requirements:
    eMessage: .[a-zA-Z1-9\-_\/?;!"`'()`\|{}]+
options:
    expose: true  

谁能帮帮我?

【问题讨论】:

  • 我认为你确实需要eMessage: "[a-zA-Z0-9_/?;!\"`'()|{}-]+"

标签: php regex symfony routing url-routing


【解决方案1】:

我认为您需要在模式周围添加引号。

bugReport:
    path:     /bugReport/{eStatusCode}/{eMessage}
    defaults: { _controller: utilisateurBundle:ExceptionReport:bugReport }    
    requirements:
        eMessage: ".[a-zA-Z1-9\-_\/?;!"`'()`\|{}]+"
    options:
        expose: true  

此正则表达式的在线演示:https://regex101.com/r/vK4rV7/1

【讨论】:

    猜你喜欢
    • 2014-06-21
    • 2019-01-09
    • 1970-01-01
    • 2016-09-25
    • 2018-07-02
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多