JS: Skip files with unsupported file encoding #6924
Merged
+12
−2
Conversation
esbena
reviewed
Oct 20, 2021
| String source = wholeIO.read(f); | ||
| if (source == null) { | ||
| if (wholeIO.getLastException() instanceof CharacterCodingException) { | ||
| System.err.println("Skipped due to unsupported character encoding: " + f); |
Would it be helpful to add the expected encoding?
Suggested change
| System.err.println("Skipped due to unsupported character encoding: " + f); | |
| System.err.println("Skipped due to unsupported character encoding (expected " + config.getDefaultEncoding().toString()+ "): " + f); |
Hm,. it's little more nuanced than that. If the file starts with a UTF-16LE or UTF-16BE byte-order mark, we use that instead. The "default" encoding is what to use if there is no byte order mark.
So the supported encodings are UTF-8 (with or without BOM) or any UTF-16 with BOM.
I see. Should we make the message more nuanced then, or is that a rabbit hole of work given how rare the problem is?
I'd rather just leave it like this.
esbena
approved these changes
Oct 22, 2021
|
Smoke test looks fine |
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.


If the contents of a file cannot be decoded using the expected charset (usually UTF-8) one or more replacement characters would get inserted, as per the default string-decoding behavior of the Java libraries. We'd then proceed to extract the file with replacement characters and all.
This PR changes it so files with any decoding errors are skipped entirely, but does not fail extraction.
An internal PR must be merged first.
The text was updated successfully, but these errors were encountered: