Skip to content
New issue

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

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

Already on GitHub? # to your account

chunk mode send json #20

Closed
hyzeer opened this issue Jul 26, 2019 · 4 comments
Closed

chunk mode send json #20

hyzeer opened this issue Jul 26, 2019 · 4 comments
Labels

Comments

@hyzeer
Copy link

hyzeer commented Jul 26, 2019

Hi , thank you very much for your wonderful framework , but I regret to find an error in processing NON-ASCII characters by using the framework .

for chunk in res:
     await resp.send('{:x}\r\n'.format(len(chunk)))
     await resp.send(chunk)
     await resp.send('\r\n')

the above codes in server.py at line 337-340 , "len(chunk)" refer to the numbers of the character variable "chunk" , not the bytes length . It's OK with the return of the function "len( )" , when the character variable is ASCII type , but for the NON-ASCII type , such as a Chinese character , the character number is 1 in function "len( )" , and the length is 3 bytes . So , this function will cause a loss in transmission .

@belyalov
Copy link
Owner

belyalov commented Jul 26, 2019

Hi @hyzeer,

thanks for reporting this issue - I never tried to send non ASCII chars through JSON, so you're totally right! :)

It actually easy to fix by

            chunk_len = len(s.encode('utf-8'))
            await resp.send('{:x}\r\n'.format(chunk_len))

The question here is - do you guys always using utf8 as default encoding?
In Russia we do use utf8 as default, so I wonder do we need to make encoding configurable or we can just hardcode it - in order to save bytecode / RAM.

@belyalov belyalov added the bug label Jul 26, 2019
@hyzeer
Copy link
Author

hyzeer commented Jul 26, 2019

Hi @belyalov , thanks for your reply.
Yes, most of us do using utf-8 as default encoding anytime. :)

Could you release new firmware after fixed? I can do it, but I not cross compile environment. Thanks!

@belyalov
Copy link
Owner

Fix just landed and new firmware is ready.

Enjoy!

@hyzeer
Copy link
Author

hyzeer commented Jul 28, 2019

Thanks! :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants