Skip to content

Commit 60c299d

Browse files
committed
fix: dot in config name
1 parent 8f1ccff commit 60c299d

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/file/source/file.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl FileSourceFile {
2727
where
2828
F: FileStoredFormat + Format + 'static,
2929
{
30-
let mut filename = if self.name.is_absolute() {
30+
let filename = if self.name.is_absolute() {
3131
self.name.clone()
3232
} else {
3333
env::current_dir()?.as_path().join(&self.name)
@@ -59,6 +59,9 @@ impl FileSourceFile {
5959
)))
6060
};
6161
}
62+
// Adding a dummy extension will make sure we will not override secondary extensions, i.e. "file.local"
63+
// This will make the following set_extension function calls to append the extension.
64+
let mut filename = add_dummy_extension(filename);
6265

6366
match format_hint {
6467
Some(format) => {
@@ -121,3 +124,18 @@ where
121124
})
122125
}
123126
}
127+
128+
fn add_dummy_extension(mut filename: PathBuf) -> PathBuf {
129+
match filename.extension() {
130+
Some(extension) => {
131+
let mut ext = extension.to_os_string();
132+
ext.push(".");
133+
ext.push("dummy");
134+
filename.set_extension(ext);
135+
}
136+
None => {
137+
filename.set_extension("dummy");
138+
}
139+
}
140+
filename
141+
}

tests/Settings2.default.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
debug = true
2+
production = false
3+
[place]
4+
name = Torre di Pisa
5+
longitude = 43.7224985
6+
latitude = 10.3970522
7+
favorite = false
8+
reviews = 3866
9+
rating = 4.5

tests/file.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ fn test_file_ext() {
5858
assert_eq!(c.get("debug").ok(), Some(true));
5959
assert_eq!(c.get("production").ok(), Some(false));
6060
}
61+
#[test]
62+
fn test_file_second_ext() {
63+
let c = Config::builder()
64+
.add_source(File::with_name("tests/Settings2.default"))
65+
.build()
66+
.unwrap();
67+
68+
assert_eq!(c.get("debug").ok(), Some(true));
69+
assert_eq!(c.get("production").ok(), Some(false));
70+
}

0 commit comments

Comments
 (0)