Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Dec 26, 2019
1 parent 699b5a0 commit 9ce78b9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 77 deletions.
67 changes: 0 additions & 67 deletions aws/awsutil/strings.go

This file was deleted.

4 changes: 2 additions & 2 deletions aws/signer/v4/header_rules.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v4

import (
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/internal/strings"
)

// validator houses a set of rule needed for validation of a
Expand Down Expand Up @@ -60,7 +60,7 @@ type patterns []string
// been found
func (p patterns) IsValid(value string) bool {
for _, pattern := range p {
if awsutil.StringHasPrefixFold(value, pattern) {
if strings.HasPrefixFold(value, pattern) {
return true
}
}
Expand Down
11 changes: 11 additions & 0 deletions internal/strings/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package strings

import (
"strings"
)

// HasPrefixFold tests whether the string s begins with prefix, interpreted as UTF-8 strings,
// under Unicode case-folding.
func HasPrefixFold(s, prefix string) bool {
return len(s) >= len(prefix) && strings.EqualFold(s[0:len(prefix)], prefix)
}
19 changes: 13 additions & 6 deletions aws/awsutil/strings_test.go → internal/strings/strings_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// +build go1.7

package awsutil
package strings

import (
"strings"
"testing"
)

func TestStringPrefixFold(t *testing.T) {
func TestHasPrefixFold(t *testing.T) {
type args struct {
s string
prefix string
Expand Down Expand Up @@ -57,18 +57,25 @@ func TestStringPrefixFold(t *testing.T) {
},
want: true,
},
"mixed-case prefixes": {
args: args{
s: "SoMe String",
prefix: "sOme",
},
want: true,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := StringHasPrefixFold(tt.args.s, tt.args.prefix); got != tt.want {
t.Errorf("StringHasPrefixFold() = %v, want %v", got, tt.want)
if got := HasPrefixFold(tt.args.s, tt.args.prefix); got != tt.want {
t.Errorf("HasPrefixFold() = %v, want %v", got, tt.want)
}
})
}
}

func BenchmarkStringHasPrefixFold(b *testing.B) {
StringHasPrefixFold("SoME string", "sOmE")
func BenchmarkHasPrefixFold(b *testing.B) {
HasPrefixFold("SoME string", "sOmE")
}

func BenchmarkHasPrefix(b *testing.B) {
Expand Down
2 changes: 2 additions & 0 deletions private/protocol/rest/rest_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.7

package rest_test

import (
Expand Down
4 changes: 2 additions & 2 deletions private/protocol/rest/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/aws/request"
awsStrings "github.com/aws/aws-sdk-go/internal/strings"
"github.com/aws/aws-sdk-go/private/protocol"
)

Expand Down Expand Up @@ -154,7 +154,7 @@ func unmarshalHeaderMap(r reflect.Value, headers http.Header, prefix string, nor
case map[string]*string: // we only support string map value types
out := map[string]*string{}
for k, v := range headers {
if awsutil.StringHasPrefixFold(k, prefix) {
if awsStrings.HasPrefixFold(k, prefix) {
if normalize == true {
k = strings.ToLower(k)
} else {
Expand Down

0 comments on commit 9ce78b9

Please sign in to comment.