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
Closed
Labels
Milestone

Comments

@touilleMan
Copy link

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
@davidism davidism added this to the 0.13 milestone Dec 5, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants