Visitar URL original
JS: Skip files with unsupported file encoding by asgerf · Pull Request #6924 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20211025232911/https://github.com/github/codeql/pull/6924
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

JS: Skip files with unsupported file encoding #6924

Merged

Conversation

@asgerf
Copy link
Contributor

@asgerf asgerf commented Oct 20, 2021

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.

String source = wholeIO.read(f);
if (source == null) {
if (wholeIO.getLastException() instanceof CharacterCodingException) {
System.err.println("Skipped due to unsupported character encoding: " + f);
Copy link
Contributor

@esbena esbena Oct 20, 2021

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);

Copy link
Contributor Author

@asgerf asgerf Oct 20, 2021

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.

Copy link
Contributor

@esbena esbena Oct 21, 2021

I see. Should we make the message more nuanced then, or is that a rabbit hole of work given how rare the problem is?

Copy link
Contributor Author

@asgerf asgerf Oct 22, 2021

I'd rather just leave it like this.

esbena
esbena approved these changes Oct 22, 2021
@asgerf
Copy link
Contributor Author

@asgerf asgerf commented Oct 25, 2021

Smoke test looks fine

@codeql-ci codeql-ci merged commit b5554da into github:main Oct 25, 2021
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants