Commit d665835

mo khan <mo@mokhan.ca>
2022-12-09 17:27:00
fix: check for duplicate attribute name
1 parent f891efc
Changed files (1)
lib
scim
lib/scim/kit/v2/attributable.rb
@@ -38,7 +38,9 @@ module Scim
         # @param name [String] the name of the attribute to return
         # @return [Scim::Kit::V2::Attribute] the attribute or {Scim::Kit::V2::UnknownAttribute}
         def attribute_for(name)
-          dynamic_attributes[name.to_s.underscore] || UnknownAttribute.new(name)
+          dynamic_attributes[name.to_s.underscore] ||
+            dynamic_attributes[name] ||
+            UnknownAttribute.new(name)
         end
 
         # Returns the value associated with the attribute name
@@ -86,11 +88,19 @@ module Scim
         end
 
         def attribute(type, resource)
-          dynamic_attributes[type.name] = Attribute.new(
-            type: type,
-            resource: resource
-          )
-          extend(create_module_for(type))
+          if dynamic_attributes.key?(type.name)
+            key = "#{type.schema&.id}##{type.name}"
+            dynamic_attributes[key] = Attribute.new(
+              type: type,
+              resource: resource
+            )
+          else
+            dynamic_attributes[type.name] = Attribute.new(
+              type: type,
+              resource: resource
+            )
+            extend(create_module_for(type))
+          end
         end
       end
     end