Skip to content

Commit dde80ff

Browse files
authoredFeb 22, 2025··
use Scanner constructor supported since Android Api Level 1 and add tests for UTF-8 values (#86)
1 parent f9989e1 commit dde80ff

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed
 

‎src/main/java/io/github/cdimascio/dotenv/internal/ClasspathHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ static Stream<String> loadFileFromClasspath(String location) {
2525
throw new DotenvException("Could not find "+location+" on the classpath");
2626
}
2727

28-
final var scanner = new Scanner(inputStream, StandardCharsets.UTF_8);
28+
final var scanner = new Scanner(inputStream, "utf-8");
2929
final var lines = new ArrayList<String>();
3030
while (scanner.hasNext()) {
3131
lines.add(scanner.nextLine());
3232
}
33-
33+
scanner.close();
3434
return lines.stream();
3535
}
3636
}

‎src/test/java/tests/BasicTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class BasicTests {
2020
put("QUOTED_VALUE", "iH4>hb_d0#_GN8d]6");
2121
put("MY_TEST_EV4", "my test ev 4");
2222
put("MULTI_LINE_WITH_SHARP", "hello\n#world");
23+
put("UTF8_STRING", "äöüßé😀");
2324
}};
2425

2526
@Test
@@ -135,6 +136,15 @@ void iterateOverDotenv() {
135136
assertEquals(dotenv.get(e.getKey()), e.getValue());
136137
}
137138
}
139+
140+
@Test
141+
void iterateOverEnvVar() {
142+
final var dotenv = Dotenv.configure()
143+
.ignoreIfMalformed()
144+
.load();
145+
146+
envVars.forEach((key, expected) -> assertEquals(expected, dotenv.get(key)));
147+
}
138148

139149
@Test
140150
void dotenvMissing() {

‎src/test/resources/.env

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ QUOTED_EV1="jdbc:hive2://[domain]:10000/default;principal=hive/_HOST@[REALM]"
2424

2525
## Test ENV that is expected to be overriden by HOME in host env
2626
HOME=dotenv_test_home
27+
28+
UTF8_STRING="äöüßé😀"

‎src/test/resources/env

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ MISSING_START_QUOTE=teste"
1919
MY_TEST_EV4="my test ev 4"
2020
MULTI_LINE_WITH_SHARP="hello
2121
#world"
22+
23+
UTF8_STRING="äöüßé😀"

0 commit comments

Comments
 (0)
Please sign in to comment.