Skip to content

fix(sql): enforce UTF-8 when loading keyword resources #1260

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -28,7 +28,9 @@ private Keywords() {}
private static Set<String> readLines(String path) {
try (var bufferedReader =
new BufferedReader(
new InputStreamReader(Keywords.class.getResourceAsStream("/keywords/" + path))); ) {
new InputStreamReader(
Keywords.class.getResourceAsStream("/keywords/" + path),
java.nio.charset.StandardCharsets.UTF_8)); ) {
return bufferedReader
.lines()
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.querydsl.sql;

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.reflect.Method;
import java.util.Set;
import org.junit.Test;

public class KeywordsEncodingTest {

@SuppressWarnings("unchecked")
@Test
public void readLines_usesUtf8() throws Exception {
Method m = Keywords.class.getDeclaredMethod("readLines", String.class);
m.setAccessible(true);
Set<String> lines = (Set<String>) m.invoke(null, "encoding-test");
assertThat(lines).containsExactly("SELECT", "ÄÖÜ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
ÄÖÜ