Skip to content

Commit

Permalink
fix: 短絡評価によるバグを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ivixvi committed Feb 12, 2025
1 parent b3328b3 commit 95565ba
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
35 changes: 34 additions & 1 deletion path_not_specified_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ func TestPathNotSpecifiedAdd(t *testing.T) {
expected map[string]interface{}
expectedChanged bool
}{
// Replace Multi Attribute
{
name: "Add operation - Core Singular Attributes - add",
op: scim.PatchOperation{
Op: "add",
Value: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
},
data: map[string]interface{}{},
expected: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
expectedChanged: true,
},
// Singular Attribute
{
name: "Add operation - Core Singular Attributes - add",
Expand Down Expand Up @@ -466,7 +499,7 @@ func TestPathNotSpecifiedAdd(t *testing.T) {
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(),tc.op, tc.data)
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
}
Expand Down
33 changes: 33 additions & 0 deletions path_not_specified_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ func TestPathNotSpecifiedReplace(t *testing.T) {
expected map[string]interface{}
expectedChanged bool
}{
// Replace Multi Attribute
{
name: "Replace operation - Core Singular Attributes - add",
op: scim.PatchOperation{
Op: "replace",
Value: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
},
data: map[string]interface{}{},
expected: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
expectedChanged: true,
},
// Singular Attribute
{
name: "Replace operation - Core Singular Attributes - add",
Expand Down
8 changes: 6 additions & 2 deletions scimpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ func (p *Patcher) pathUnspecifiedOperate(
uriPrefix, ok := p.schemas[attr]
// Core Attributes
if !ok {
changed = changed || operator.Direct(ctx, data, attr, value)
if operator.Direct(ctx, data, attr, value) {
changed = true
}
continue
}

Expand All @@ -195,7 +197,9 @@ func (p *Patcher) pathUnspecifiedOperate(
// if exists, write by every attributes
if newUriMap, ok := value.(map[string]interface{}); ok {
for scopedAttr, scopedValue := range newUriMap {
changed = changed || operator.Direct(ctx, oldMap, scopedAttr, scopedValue)
if operator.Direct(ctx, oldMap, scopedAttr, scopedValue) {
changed = true
}
}
}
}
Expand Down

0 comments on commit 95565ba

Please sign in to comment.