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 Content-Length return wrong length #129

Merged
merged 1 commit into from
May 1, 2014
Merged

Conversation

ajaxsys
Copy link
Contributor

@ajaxsys ajaxsys commented May 1, 2014

Hi, thanks for creating this awesome tool. I got a bug when using JSCover.

In Proxy mode, Content-Length return wrong length in some Unicode cases.

For example:
"小方".length() // Output: 2
"小方".getBytes("UTF-8").length // Output: 6

As Content-Length defines the size of the body,
in above case data.length() always return the shorter length,
so _the browser will cut the left JavaScript code_ that causes syntax errors.
(Tested in chrome/Firefox).

Change to data.getBytes().length, parsing with bytes using the platform's default charset,
will get correct length.

*Content-Length Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13

In Proxy mode, Content-Length return wrong length in some Unicode cases.

For example:
"小方".length() // Output: 2
"小方".getBytes("UTF-8").length // Output: 6

As `Content-Length` defines the size of the body,
in above case `data.length()` always return the shorter length, 
so the browser will cut left JavaScript code(Tested in chrome/Firefox).

Change to `data.getBytes().length`, parsing with bytes using the platform's default charset,
will get correct length.

*Content-Length Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
@tntim96
Copy link
Owner

tntim96 commented May 1, 2014

Thanks will check it soon. Would be nice to have a test case, but I can add that.
Cheers.

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

Successfully merging this pull request may close these issues.

2 participants