Skip to content

Commit c912221

Browse files
committed
feat: treate space as falsy value from env variable
1 parent 9db1861 commit c912221

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/util/env.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ func isTruthyEnvValue(value string) bool {
2121
}
2222

2323
for i := 0; i < valueLen; i++ {
24-
if value[i] != '0' {
24+
if value[i] != '0' &&
25+
value[i] != ' ' &&
26+
value[i] != '\t' &&
27+
value[i] != '\f' &&
28+
value[i] != '\r' &&
29+
value[i] != '\n' {
2530
return true
2631
}
2732
}

src/util/env_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ func TestIsTruthyEnvValue(t *testing.T) {
3939
if !expect("0000", false) {
4040
t.Error()
4141
}
42+
43+
if !expect(" ", false) {
44+
t.Error()
45+
}
46+
47+
if !expect(" 0", false) {
48+
t.Error()
49+
}
4250
}

0 commit comments

Comments
 (0)