bool/stringslice: 想定外入力のサイレントなフォールバックを改善 (#18)#27
Merged
Conversation
## 理由
Bool は {true,t,1} 以外を全て false に潰し、def=true でも誤綴りの値で無音 false 化
していた。StringSlice は空文字列の env に対し [""] を返し、unset 時の [] と非対称
だった(#18)。下流のサイレントな設定不具合を防ぐため、許容値を広げ未知入力を
可視化し、空値の扱いを揃える。
## 修正点
- Bool: truthy に yes/on/y、falsy に no/off/n/false/f/0 を追加し、前後空白 trim・
大文字小文字無視。convertStringToBoolean を (値, 認識可否) に変更し、認識できない
値はデフォルト値を維持して log 警告(生値は出さない)
- StringSlice: 空文字列の env を unset と同等に扱い(デフォルト or 空スライス)、
非空は分割後に各要素を TrimSpace し空要素を除去("a, b," -> ["a","b"])
- bool_test.go / string_test.go を新挙動に合わせ更新・ケース追加
- README(en/jp)に Bool / StringSlice のセマンティクスを明記
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Bool / StringSlice が想定外入力に対してサイレントにフォールバックする挙動を改善します。
Closes #18
背景(監査検出)
{true,t,1}以外を全て false に潰し、Bool("X", true)でも値がセットされていれば誤綴り(on等)で無音 false 化。defを無視するフットガンstrings.Split("",",")で[""](長さ1)を返し、unset 時の[](長さ0)と非対称。"a,"の末尾空要素も残る変更点(方針: 許容値拡張 + 未知はデフォルト維持 / 空は[]・trim・空要素除去)
Bool
yes/on/y、falsy にno/off/n/false/f/0を追加、前後空白 trim・大文字小文字無視convertStringToBooleanを(値, 認識可否)に変更し、認識できない値はデフォルト値を維持(+ log 警告)。def=trueにmaybeを渡しても無音 false に潰れないoff→false、yes→true)StringSlice
TrimSpaceし空要素を除去(" a , b , ,c,"→["a","b","c"])ドキュメント: README(en/jp)に両者のセマンティクスを明記
後方互換 / 挙動変更
true/false等)の結果は不変Bool("X", true)でX=garbage→ 従来 false / 変更後 true(デフォルト維持)。X=yes→ 従来 false / 変更後 true。StringSliceの空文字 env → 従来[""]/ 変更後[](or デフォルト)テスト
bool_test.go/string_test.goを新挙動に合わせ更新・ケース追加(空値・trim・空要素除去・未知値フォールバック・生値非出力)go build/go vet/go test/go test -raceすべて ✅、変更ファイルは gofmt クリーン🤖 Generated with Claude Code