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

update asgi.py replace the latin-1 with utf-8. #1837

Closed

Conversation

SchopenhauerZhang
Copy link

for avoid another unicode warn or error,please use utf-8.Thanks!
latin-1 with utf-8 difference.:https://stackoverflow.com/questions/7048745/what-is-the-difference-between-utf-8-and-iso-8859-1/39109074

@codecov
Copy link

codecov bot commented Apr 30, 2020

Codecov Report

Merging #1837 into master will decrease coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1837      +/-   ##
==========================================
- Coverage   92.06%   91.97%   -0.10%     
==========================================
  Files          27       27              
  Lines        3089     3089              
  Branches      552      552              
==========================================
- Hits         2844     2841       -3     
- Misses        171      173       +2     
- Partials       74       75       +1     
Impacted Files Coverage Δ
sanic/asgi.py 93.01% <100.00%> (ø)
sanic/server.py 78.47% <0.00%> (-0.58%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ee8ee7...a54e7b2. Read the comment docs.

@Tronic
Copy link
Member

Tronic commented Apr 30, 2020

Yes, the path property of ASGI scope is in UTF-8 but I think this re-encoding should be avoided entirely by using something like:

url_bytes = b"%b?%b" % (scope["raw_path"], scope["query_string"])

I believe that root_path being included in existing code is a mistake, so I left that out (which may be a breaking change). Any comments from other devs or ASGI users?

@ahopkins
Copy link
Member

I'll do another survey of other implementations and the spec. But I believe that is correct.

@ahopkins ahopkins marked this pull request as draft May 17, 2020 14:42
@Tronic
Copy link
Member

Tronic commented Jun 21, 2020

Yes, the path property of ASGI scope is in UTF-8 but I think this re-encoding should be avoided entirely by using something like:

url_bytes = b"%b?%b" % (scope["raw_path"], scope["query_string"])

I believe that root_path being included in existing code is a mistake, so I left that out (which may be a breaking change).

@SchopenhauerZhang could you implement and test this change, so that we could get this merged?

@ahopkins
Copy link
Member

Ping @SchopenhauerZhang

@ashleysommer
Copy link
Member

I agree with @Tronic here.
We probably don't need to re-encode the url to bytes if we already have the raw_path available in the correct encoding anyway.
The only thing I'm not sure about, is the current implementation does url-encode the scope['path'] using quote(path) before adding it to the root_path, I'm not familiar enough with ASGI to know if/why that is required.

@stale
Copy link

stale bot commented Dec 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.

@stale stale bot added the stale label Dec 19, 2020
@ahopkins ahopkins removed the stale label Dec 24, 2020
@ahopkins
Copy link
Member

I am closing this. If someone thinks there is something we still need here, please reopen a new PR.

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.

4 participants