Skip to content

Commit

Permalink
chore: replace case conversion with equal fold (#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge authored Nov 13, 2024
1 parent 4a57395 commit 3257ea3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ var (
return err
}
if len(args) > 0 {
name := strings.ToLower(args[0])
name := args[0]
for _, t := range templates {
if t.Name == name {
if strings.EqualFold(t.Name, name) {
starter = t
break
}
}
if name != starter.Name {
return errors.New("Invalid template: " + args[0])
if !strings.EqualFold(starter.Name, name) {
return errors.New("Invalid template: " + name)
}
} else {
if err := promptStarterTemplate(ctx, templates); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/sso/internal/saml/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func ValidateMetadataURL(ctx context.Context, metadataURL string) error {
return errors.Errorf("failed to parse metadata uri: %w", err)
}

if strings.ToLower(parsed.Scheme) != "https" {
if !strings.EqualFold(parsed.Scheme, "https") {
return errors.New("only HTTPS Metadata URLs are supported")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/storage/client/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ParseStorageURL(objectURL string) (string, error) {
if err != nil {
return "", errors.Errorf("failed to parse storage url: %w", err)
}
if strings.ToLower(parsed.Scheme) != STORAGE_SCHEME || len(parsed.Path) == 0 || len(parsed.Host) > 0 {
if !strings.EqualFold(parsed.Scheme, STORAGE_SCHEME) || len(parsed.Path) == 0 || len(parsed.Host) > 0 {
return "", errors.New(ErrInvalidURL)
}
return parsed.Path, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/storage/cp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Run(ctx context.Context, src, dst string, recursive bool, maxJobs uint, fsy
if err != nil {
return err
}
if strings.ToLower(srcParsed.Scheme) == client.STORAGE_SCHEME && dstParsed.Scheme == "" {
if strings.EqualFold(srcParsed.Scheme, client.STORAGE_SCHEME) && dstParsed.Scheme == "" {
localPath := dst
if !filepath.IsAbs(dst) {
localPath = filepath.Join(utils.CurrentDirAbs, dst)
Expand All @@ -44,7 +44,7 @@ func Run(ctx context.Context, src, dst string, recursive bool, maxJobs uint, fsy
return DownloadStorageObjectAll(ctx, api, srcParsed.Path, localPath, maxJobs, fsys)
}
return api.DownloadObject(ctx, srcParsed.Path, localPath, fsys)
} else if srcParsed.Scheme == "" && strings.ToLower(dstParsed.Scheme) == client.STORAGE_SCHEME {
} else if srcParsed.Scheme == "" && strings.EqualFold(dstParsed.Scheme, client.STORAGE_SCHEME) {
localPath := src
if !filepath.IsAbs(localPath) {
localPath = filepath.Join(utils.CurrentDirAbs, localPath)
Expand All @@ -53,7 +53,7 @@ func Run(ctx context.Context, src, dst string, recursive bool, maxJobs uint, fsy
return UploadStorageObjectAll(ctx, api, dstParsed.Path, localPath, maxJobs, fsys, opts...)
}
return api.UploadObject(ctx, dstParsed.Path, src, fsys, opts...)
} else if strings.ToLower(srcParsed.Scheme) == client.STORAGE_SCHEME && strings.ToLower(dstParsed.Scheme) == client.STORAGE_SCHEME {
} else if strings.EqualFold(srcParsed.Scheme, client.STORAGE_SCHEME) && strings.EqualFold(dstParsed.Scheme, client.STORAGE_SCHEME) {
return errors.New("Copying between buckets is not supported")
}
utils.CmdSuggestion = fmt.Sprintf("Run %s to copy between local directories.", utils.Aqua("cp -r <src> <dst>"))
Expand Down
4 changes: 2 additions & 2 deletions pkg/parser/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *ReadyState) Next(r rune, data []byte) State {
fallthrough
case 'C':
offset := len(data) - len(BEGIN_ATOMIC)
if offset >= 0 && strings.ToUpper(string(data[offset:])) == BEGIN_ATOMIC {
if offset >= 0 && strings.EqualFold(string(data[offset:]), BEGIN_ATOMIC) {
return &AtomicState{prev: s, delimiter: []byte(END_ATOMIC)}
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *AtomicState) Next(r rune, data []byte) State {
if _, ok := s.prev.(*ReadyState); ok {
window := data[len(data)-len(s.delimiter):]
// Treat delimiter as case insensitive
if strings.ToUpper(string(window)) == string(s.delimiter) {
if strings.EqualFold(string(window), string(s.delimiter)) {
return &ReadyState{}
}
}
Expand Down

0 comments on commit 3257ea3

Please sign in to comment.