Skip to content

Commit

Permalink
Merge pull request #306 from CfirTsabari/cfirtsabari/doesn-t-work-wit…
Browse files Browse the repository at this point in the history
…h-dot-101

fix: dot in config name
  • Loading branch information
matthiasbeyer authored Apr 10, 2022
2 parents 664f07b + 34ea07a commit 44a1216
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/file/source/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl FileSourceFile {
where
F: FileStoredFormat + Format + 'static,
{
let mut filename = if self.name.is_absolute() {
let filename = if self.name.is_absolute() {
self.name.clone()
} else {
env::current_dir()?.as_path().join(&self.name)
Expand Down Expand Up @@ -59,6 +59,9 @@ impl FileSourceFile {
)))
};
}
// Adding a dummy extension will make sure we will not override secondary extensions, i.e. "file.local"
// This will make the following set_extension function calls to append the extension.
let mut filename = add_dummy_extension(filename);

match format_hint {
Some(format) => {
Expand Down Expand Up @@ -121,3 +124,18 @@ where
})
}
}

fn add_dummy_extension(mut filename: PathBuf) -> PathBuf {
match filename.extension() {
Some(extension) => {
let mut ext = extension.to_os_string();
ext.push(".");
ext.push("dummy");
filename.set_extension(ext);
}
None => {
filename.set_extension("dummy");
}
}
filename
}
9 changes: 9 additions & 0 deletions tests/Settings2.default.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
debug = true
production = false
[place]
name = Torre di Pisa
longitude = 43.7224985
latitude = 10.3970522
favorite = false
reviews = 3866
rating = 4.5
10 changes: 10 additions & 0 deletions tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ fn test_file_ext() {
assert_eq!(c.get("debug").ok(), Some(true));
assert_eq!(c.get("production").ok(), Some(false));
}
#[test]
fn test_file_second_ext() {
let c = Config::builder()
.add_source(File::with_name("tests/Settings2.default"))
.build()
.unwrap();

assert_eq!(c.get("debug").ok(), Some(true));
assert_eq!(c.get("production").ok(), Some(false));
}

0 comments on commit 44a1216

Please sign in to comment.