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

Wrong char count in ServletOutputStream with non-ASCII characters skips content #18009

Closed
barulheira opened this issue Jul 29, 2021 · 3 comments
Assignees
Labels
bug This bug is not present in a released version of Open Liberty Needs member attention release bug This bug is present in a released version of Open Liberty release:21009

Comments

@barulheira
Copy link

The ServletOutputStream skips the last chars when using print or println to print content with multi-byte characters in UTF-8.
The amount of chars skipped matches the difference between char count and byte count, on each print or println.
It doesn't matter whether it's done in the end of the response.
Changing to another encoding (e. g. ISO-8859-1) doesn't fix this.
No problem when using write instead of print.
No problem when using only ASCII characters.
No problem when using PrintWriter response.getWriter().

Steps to Reproduce
Get a response.getOutputStream() and print some text with non-ASCII content.
On each print or println, some characters will be skipped in the end.
out.println("'ATENÇÃO!'"); // Skips last 2 characters
will print out:
'ATENÇÃO
A minimal web app is attached.

Expected behavior
It should print: 'ATENÇÃO!'

Diagnostic information:
Open Liberty 21.0.0.7

Additional context
This s.length() here may be the cause:


bug.zip

Thanks @Thihup

@barulheira barulheira added the bug This bug is not present in a released version of Open Liberty label Jul 29, 2021
@pnicolucci pnicolucci added the release bug This bug is present in a released version of Open Liberty label Aug 2, 2021
@wtlucy
Copy link
Contributor

wtlucy commented Aug 2, 2021

Thanks for reporting this @barulheira - you're correct, the WCOutputStream should be writing the length of the encoded bytes rather than the length of the original string.

@wtlucy
Copy link
Contributor

wtlucy commented Aug 5, 2021

This is fixed with #18022. @barulheira if you'd like to verify the behavior you can check out this build, otherwise the fix will be in the 21.0.0.9 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This bug is not present in a released version of Open Liberty Needs member attention release bug This bug is present in a released version of Open Liberty release:21009
Projects
Archived in project
Development

No branches or pull requests

6 participants