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

Response.calculate_content_length doesn't use encoded self.response #705

Closed
touilleMan opened this issue Mar 14, 2015 · 0 comments

Comments

Projects
None yet
3 participants
@touilleMan
Copy link

commented Mar 14, 2015

The implementation of calculate_content_length doesn't encode the elements of self.response before using them:
https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/wrappers.py#L926

    def calculate_content_length(self):
        [...]
        return sum(len(x) for x in self.response)

In case self.response is composed of utf-8 encoded unicode strings, this will lead to an invalid return length:

>>> from werkzeug import Response
>>> r = Response()
>>> r.response.append(u'你好')
>>> r.calculate_content_length()
2
>>> len(u'你好'.encode('utf-8'))
6

The easier solution to this would be to use iter_encoded inside calculate_content_length, but would decrease performances given the data would be encoded two time (for calculating content-lenght, then for actualy writing the data)

@untitaker untitaker added the bug label Mar 20, 2015

alexpantyukhin added a commit to alexpantyukhin/werkzeug that referenced this issue Aug 13, 2016

alexpantyukhin added a commit to alexpantyukhin/werkzeug that referenced this issue Aug 20, 2016

@untitaker untitaker closed this in e4730ef May 5, 2017

@davidism davidism added this to the 0.13 milestone Dec 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.