开发者

Symfony2 routing: problem with line breaks

I have a routing pattern in which the last parameter is filled from a multiline input field. When I call the route wit开发者_如何转开发hout line break, everything works, but I get an error when I have a linebreak (which is escaped as %0A):

No route found for "GET /update/1/complete/Kommentar%3Daa%0Abb%7C&quot

The routing definition:

_update:
    pattern:   /update/{id}/{column}/{newvalue}
    defaults: { _controller: MyBundle:Auftrag:update, newvalue: ' ' }    
    requirements:
        id:  \d+   
        newvalue: ".+"

My controller definition is:

public function updateAction($id, $column, $newvalue) {
}


you should be aware that according to the REST idea you don't initiate a change via GET. For update you would use POST for example and then your newline-problem is solved.

I also made the experience that urlencoded chars will get interpreted. For example a urlencoded slash gets interpreted as a path separator. Don't know why, I guess it's due to server settings at the end of the day. So the solution would be there somewhere.

If you insist to use your way you could replace problem chars by combinations of ",","-","_". but that would be just a hack. use POST instead for the transmitted data.


It's seems to be a bug in Symfony route compiler. I opened a pull request on github Symfony repository, let's see if it gets accepted.. in the meanwhile, you can solve this issue by modifying Component/Routing/RouteCompiler.php:

sprintf("#^\n%s$#x", $regex), // line 99

becomes

sprintf("#^\n%s$#xm", $regex),
------------------^

Hope it helps. Alberto

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜