Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8494aa9

Browse files
committed
chore: return safe copy of string slice in 'ParseStringSliceClaim'
Claims parsed should be safe to mutate and filter. This was likelynot causing any bugs or issues, and just doing this out of precaution
1 parent5e4050e commit8494aa9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎coderd/idpsync/idpsync.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ func ParseStringSliceClaim(claim interface{}) ([]string, error) {
186186
// The simple case is the type is exactly what we expected
187187
asStringArray,ok:=claim.([]string)
188188
ifok {
189-
returnasStringArray,nil
189+
cpy:=make([]string,len(asStringArray))
190+
copy(cpy,asStringArray)
191+
returncpy,nil
190192
}
191193

192194
asArray,ok:=claim.([]interface{})

‎coderd/idpsync/idpsync_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ func TestParseStringSliceClaim(t *testing.T) {
136136
}
137137
}
138138

139+
funcTestParseStringSliceClaimReference(t*testing.T) {
140+
t.Parallel()
141+
142+
varvalany= []string{"a","b","c"}
143+
parsed,err:=idpsync.ParseStringSliceClaim(val)
144+
require.NoError(t,err)
145+
146+
parsed[0]=""
147+
require.Equal(t,"a",val.([]string)[0],"should not modify original value")
148+
}
149+
139150
funcTestIsHTTPError(t*testing.T) {
140151
t.Parallel()
141152

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp