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

Fix UTF bom parsing #9927

Merged
merged 7 commits into from
May 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ private static Optional<Charset> getSuppliedEncoding(BufferedReader reader) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();

// % = char 37, we might have some bom chars in front that we need to skip, so we use index of
var percentPos = line.indexOf('%', 0);
// Line does not start with %, so there are no comment lines for us and we can stop parsing
if (!line.startsWith("%")) {
if (percentPos == -1) {
return Optional.empty();
}

// Only keep the part after %
line = line.substring(1).trim();
line = line.substring(percentPos+1).trim();
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved

if (line.startsWith(BibtexImporter.SIGNATURE)) {
// Signature line, so keep reading and skip to next line
Expand Down