Skip to content

Commit 8e5fab5

Browse files
committed
Trim whitespace on properties file path
1 parent b4ed940 commit 8e5fab5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log
2424
@Override
2525
public @Nullable Properties load() {
2626
try {
27-
final File f = new File(filePath);
27+
final File f = new File(filePath.trim());
2828
if (f.isFile() && f.canRead()) {
2929
try (InputStream is = new BufferedInputStream(new FileInputStream(f))) {
3030
final Properties properties = new Properties();
@@ -38,7 +38,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log
3838
logger.log(
3939
SentryLevel.ERROR, "Failed to load Sentry configuration since it is not readable: %s", filePath);
4040
}
41-
} catch (IOException e) {
41+
} catch (Throwable e) {
4242
logger.log(
4343
SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", filePath);
4444
return null;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ 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 = FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance())
30+
val properties = loader.load()
31+
assertNotNull(properties)
32+
assertEquals("some-dsn", properties["dsn"])
33+
}
34+
2535
@Test
2636
fun `returns null when property file not found`() {
2737
val loader =

0 commit comments

Comments
 (0)