- literal @s can now be escaped with a preceeding backslash
- use case e.g. `--env HTTPS_PROXY=user:pass\@myproxy.com`
- if the last char before a non-literal @ (designating a following
nodefilter) is a backslash, then it can be escaped with another
backslash (no cascading escapes though)
// Case 1: There's a '\' just before the '@' sign -> Should it be escaped (aka be a literal '@')?
ifstrings.HasSuffix(it,"\\")&&i!=len(split)-1{
// Case 1.1: Escaped backslash
ifstrings.HasSuffix(it,"\\\\"){
it=strings.TrimSuffix(it,"\\")
log.Warnf("The part '%s' of the flag input '%s' ends with a double backslash, so we assume you want to escape the backslash before the '@'. That's the only time we do this.",it,flag)
}else{
// Case 1.2: Unescaped backslash -> Escaping the '@' -> remove suffix and append it to buffer, followed by the escaped @ sign
log.Tracef("Item '%s' just before an '@' ends with '\\', so we assume it's escaping a literal '@'",it)
buffer+=strings.TrimSuffix(it,"\\")+"@"
continue
}
}
// Case 2: There's no '\': append item to buffer, save it to new slice, empty buffer and continue
newsplit=append(newsplit,buffer+it)
buffer=""
continue
}
// max number of pieces after split = 2 (only one @ allowed in flag)
// max number of pieces after split = 2 (only one @ allowed in flag)
iflen(split)>2{
iflen(newsplit)>2{
return"",nil,fmt.Errorf("Invalid flag '%s': only one '@' for node filter allowed",flag)
return"",nil,fmt.Errorf("Invalid flag '%s': only one unescaped '@' allowed for node filter(s) (Escape literal '@' with '\\')",flag)
}
}
// trailing or leading '@'
// trailing or leading '@'
iflen(split)<2{
iflen(newsplit)<2{
return"",nil,fmt.Errorf("Invalid flag '%s' includes '@' but is missing either an object or a filter",flag)
return"",nil,fmt.Errorf("Invalid flag '%s' includes unescaped '@' but is missing a node filter (Escape literal '@' with '\\')",flag)