Skip to content

Commit

Permalink
Replacing field values using the complex_variant = True option is not…
Browse files Browse the repository at this point in the history
… case sensitive.

If the field name to be replaced contains uppercase letters, the comparison will fail because of the following code

if field.get('field', 'name') == name:

The first part of the comparison may contain uppercase letters. The latter part is typically lower case, but for safety reasons, I apply lower() as well. This PR contains the fix and also squashes some trailing white spaces.
  • Loading branch information
set-soft committed Jan 2, 2024
1 parent 519dd24 commit c73c665
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kibom/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,17 @@ def getValueSort(self):
def setField(self, name, value):
""" Set the value of the specified field """

name = name.lower()
# Description field
doc = self.element.getChild('libsource')
if doc:
for att_name, att_value in doc.attributes.items():
if att_name.lower() == name.lower():
if att_name.lower() == name:
doc.attributes[att_name] = value
return value

# Common fields
field = self.element.getChild(name.lower())
field = self.element.getChild(name)
if field:
field.setChars(value)
return value
Expand All @@ -258,7 +259,7 @@ def setField(self, name, value):
fields = self.element.getChild('fields')
if fields:
for field in fields.getChildren():
if field.get('field', 'name') == name:
if field.get('field', 'name').lower() == name:
field.setChars(value)
return value

Expand Down

0 comments on commit c73c665

Please sign in to comment.