Skip to content

Commit

Permalink
*: strings.Title deprecation
Browse files Browse the repository at this point in the history
Replace with simple manual construction of upper boolean
representation, as the (construction of the) `golang.org/x/text/cases`
replacement is way too complex for this use case.

Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Aug 23, 2023
1 parent 7e487fa commit 92aa55f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions aes/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
"fmt"
"regexp"
"strconv"
"strings"

"github.com/sirupsen/logrus"
"github.com/getsops/sops/v3"
"github.com/getsops/sops/v3/logging"
"github.com/sirupsen/logrus"
)

var log *logrus.Logger
Expand Down Expand Up @@ -172,7 +171,11 @@ func (c Cipher) Encrypt(plaintext interface{}, key []byte, additionalData string
case bool:
encryptedType = "bool"
// The Python version encodes booleans with Titlecase
plainBytes = []byte(strings.Title(strconv.FormatBool(value)))
if value {
plainBytes = []byte("True")
} else {
plainBytes = []byte("False")
}
case sops.Comment:
encryptedType = "comment"
plainBytes = []byte(value.Value)
Expand Down
8 changes: 6 additions & 2 deletions sops.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"
"github.com/getsops/sops/v3/audit"
"github.com/getsops/sops/v3/keys"
"github.com/getsops/sops/v3/keyservice"
"github.com/getsops/sops/v3/logging"
"github.com/getsops/sops/v3/shamir"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -727,7 +727,11 @@ func ToBytes(in interface{}) ([]byte, error) {
case float64:
return []byte(strconv.FormatFloat(in, 'f', -1, 64)), nil
case bool:
return []byte(strings.Title(strconv.FormatBool(in))), nil
boolB := []byte("True")
if !in {
boolB = []byte("False")
}
return boolB, nil
case []byte:
return in, nil
case Comment:
Expand Down

0 comments on commit 92aa55f

Please sign in to comment.