Skip to content

Commit

Permalink
Improve utf8 detection (#12342)
Browse files Browse the repository at this point in the history
* improve utf8 detction with confidence

* changelog

* refine comment
  • Loading branch information
Siedlerchr authored Dec 30, 2024
1 parent c8b705b commit 92ba3cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Fixed

- We fixed an issue where a bib file with UFF-8 charset was wrongly loaded with a different charset [forum#5369](https://discourse.jabref.org/t/jabref-5-15-opens-bib-files-with-shift-jis-encoding-instead-of-utf-8/5369/)

### Removed

## [6.0-alpha] – 2024-12-23
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/importer/Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ protected static Charset getCharset(BufferedInputStream bufferedInputStream) {
return defaultCharSet;
}

if (Arrays.stream(matches).anyMatch(charset -> "ASCII".equals(charset.getName()))) {
// if we have utf8 with 100 confidence we assume that the file is in utf8, more likely
if (Arrays.stream(matches).anyMatch(charset -> "ASCII".equals(charset.getName()) || ("UTF-8".equals(charset.getName()) && charset.getConfidence() == 100))) {
return defaultCharSet;
}

Expand Down

0 comments on commit 92ba3cd

Please sign in to comment.