Skip to content

Commit 8b95cbe

Browse files
authored
fix(config): Trim whitespace on properties path (#4880)
* Trim whitespace on properties file path * format * changelog
1 parent b572714 commit 8b95cbe

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Removed SentryExecutorService limit for delayed scheduled tasks ([#4846](https://github.com/getsentry/sentry-java/pull/4846))
88
- Fix visual artifacts for the Canvas strategy on some devices ([#4861](https://github.com/getsentry/sentry-java/pull/4861))
9+
- [Config] Trim whitespace on properties path ([#4880](https://github.com/getsentry/sentry-java/pull/4880))
910
- Only set `DefaultReplayBreadcrumbConverter` if replay is available ([#4888](https://github.com/getsentry/sentry-java/pull/4888))
1011

1112
### Improvements

sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.BufferedInputStream;
66
import java.io.File;
77
import java.io.FileInputStream;
8-
import java.io.IOException;
98
import java.io.InputStream;
109
import java.util.Properties;
1110
import org.jetbrains.annotations.NotNull;
@@ -24,7 +23,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log
2423
@Override
2524
public @Nullable Properties load() {
2625
try {
27-
final File f = new File(filePath);
26+
final File f = new File(filePath.trim());
2827
if (f.isFile() && f.canRead()) {
2928
try (InputStream is = new BufferedInputStream(new FileInputStream(f))) {
3029
final Properties properties = new Properties();
@@ -42,7 +41,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log
4241
"Failed to load Sentry configuration since it is not readable: %s",
4342
filePath);
4443
}
45-
} catch (IOException e) {
44+
} catch (Throwable e) {
4645
logger.log(
4746
SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", filePath);
4847
return null;

sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ class FilesystemPropertiesLoaderTest {
2222
assertEquals("some-dsn", properties["dsn"])
2323
}
2424

25+
@Test
26+
fun `returns properties when file has whitespace`() {
27+
val file = folder.newFile("sentry.properties")
28+
file.writeText("dsn=some-dsn", Charset.defaultCharset())
29+
val loader =
30+
FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance())
31+
val properties = loader.load()
32+
assertNotNull(properties)
33+
assertEquals("some-dsn", properties["dsn"])
34+
}
35+
2536
@Test
2637
fun `returns null when property file not found`() {
2738
val loader =

0 commit comments

Comments
 (0)