diff --git a/conf.v b/conf.v index 65c0a16..0cb2250 100644 --- a/conf.v +++ b/conf.v @@ -102,8 +102,11 @@ pub fn load(ld LoadConfig) !T { } // Finally, if there's no env var present either, we check whether the - // variable has a default value - if !has_value.exists(field.name) { + // variable has a default value. Variables defined with an "empty + // default" will always be marked as containing a value. + if 'empty_default' in field.attrs { + has_value.add(field.name) + } else if !has_value.exists(field.name) { mut has_default := false $if field.typ is string { diff --git a/string_test.v b/string_test.v index 46cb85d..9dfc191 100644 --- a/string_test.v +++ b/string_test.v @@ -170,3 +170,14 @@ fn test_string_absent_default_env() { some_string: 'env' } } + +struct SingleConfDefaultEmpty { + some_string string [empty_default] +} + +fn test_string_absent_default_empty() { + conf := load(default_path: 'test/empty.toml')! + assert conf == SingleConfDefaultEmpty{ + some_string: '' + } +}