Allow value prefixed with bang to skip parsing

This commit is contained in:
Dan Jones 2024-10-31 14:31:16 -05:00
commit a8cbfd087f
2 changed files with 8 additions and 0 deletions

View file

@ -17,6 +17,10 @@ func ParseString(in string) any {
return s
}
if strings.HasPrefix(s, "!") {
return strings.TrimPrefix(s, "!")
}
yesno := regexp.MustCompile("^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$")
yes := regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$")
null := regexp.MustCompile("^(~|null|Null|NULL|none|None|NONE|nil|Nil|NIL)$")

View file

@ -38,6 +38,10 @@ func TestParse(t *testing.T) {
{"on-value", "on", true},
{"no-value", "no", false},
{"off-value", "off", false},
{"skip-parsing-num", "!42", "42"},
{"skip-parsing-bool", "!false", "false"},
{"skip-parsing-time", "!" + when.Format(time.RFC3339), when.Format(time.RFC3339)},
{"skip-parsing-duration", "!15 mins", "15 mins"},
}
for _, tt := range tests {