Fix encoding of non-ascii contents written to parameter files.#18972
Closed
zhengwei143 wants to merge 5 commits intobazelbuild:masterfrom
Closed
Fix encoding of non-ascii contents written to parameter files.#18972zhengwei143 wants to merge 5 commits intobazelbuild:masterfrom
zhengwei143 wants to merge 5 commits intobazelbuild:masterfrom
Conversation
55ac165 to
deef072
Compare
deef072 to
0762612
Compare
Contributor
Author
|
Potential fix for #18792 |
coeuvre
approved these changes
Jul 19, 2023
tetromino
requested changes
Jul 21, 2023
Contributor
There was a problem hiding this comment.
This seems logically correct but inefficient: writeContentUtf8 is a private method which has exactly 1 call site, so we can certainly avoid double-recoding.
I would suggest reverting the change to writeContent(), and instead changing writeContentUtf8() to the following:
...
if (stringUnsafe.getCoder(line) == StringUnsafe.LATIN1 && isAscii(bytes)) {
outputStream.write(bytes);
} else if (!StringUtil.decodeBytestringUtf8(line).equals(line)) {
// We successfully decoded line from utf8 - meaning it was already encoded as utf8.
// We do not want to double-encode.
outputStream.write(bytes);
} else {
ByteBuffer encodedBytes = encoder.encode(CharBuffer.wrap(line));
...
tetromino
approved these changes
Jul 21, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When args are written to parameter files, non-ascii values are wrongly encoded again as utf-8. This seems to be unaffected by the JDK20 upgrade of Bazel, and has always been happening.
Repro: