Skip to content

fix: dot in config name #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}