Maddy
Maddy

Reputation: 831

Tornado url regex unicode chars

I have a tornado application, where the url is something like

https://example.com/my/path/❤

In tornado I have

handlers = [
        (r'/my/path/❤$', MyHandler),
]

but it is not matching with the path.

I tried tornado.escape.utf8() and tornado.escape.url_escape() with no luck.

If I replace %E2%9D%A4 which is encoded string of then it works is it possible to make it work without replacing it to encoded string?

Upvotes: 1

Views: 713

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22154

No, tornado's routing engine currently works on the encoded form of the urls, so it is impractical to use non-ascii characters in routes. (They work fine if captured as a variable part of the path, so r'/my/path/(.*)' would correctly capture and pass it as the first argument to the handler).

Handling unicode routes is a longstanding feature request, but it is difficult to solve correctly because of the complexity of the rules defined in RFC 3987.

Upvotes: 2

Related Questions