Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: the Chinese URI #1081

Merged
merged 6 commits into from
Jan 8, 2018
Merged

Fix: the Chinese URI #1081

merged 6 commits into from
Jan 8, 2018

Conversation

howie6879
Copy link
Contributor

@howie6879 howie6879 commented Jan 7, 2018

Hello,
I have a question about routing, for example:

from sanic import Sanic
from sanic.response import text, redirect


app = Sanic()


@app.route("/你好")
async def test(request):
    return text('你好')

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

# Visit:http://0.0.0.0:8000/你好
# Output: Error: Requested URL /%E4%BD%A0%E5%A5%BD not found

Maybe we could use the unquote() to solve this problem

# Visit:http://0.0.0.0:8000/你好
# Output: 你好

sanic/router.py Outdated
@@ -373,6 +374,7 @@ def _get(self, url, method, host):
:param method: request method
:return: handler, arguments, keyword arguments
"""
url = unquote(url)
url = host + url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you switch this to url = unquote(host + url)?

@r0fls
Copy link
Contributor

r0fls commented Jan 7, 2018

@howie6879 can you also please add the below unit test to tests/test_routes.py:

def test_unicode_routes():                                                                                                  
    app = Sanic('test_unicode_routes')                                                                                      
                                                                                                                            
    @app.get('/你好')                                                                                                       
    def handler(request):                                                                                                   
        return text('OK')                                                                                                   
                                                                                                                            
    request, response = app.test_client.get('/你好')                                                                        
    assert response.text == 'OK'   

@howie6879
Copy link
Contributor Author

@r0fls Done😊

@r0fls r0fls merged commit 9f55981 into sanic-org:master Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants