Skip to content

Commit

Permalink
Use get(..) instead of [..] for safe lookup of value (Fixed #7240)
Browse files Browse the repository at this point in the history
A OnePassword field item might not have a value (property) when the user has omitted it (on purpose).
  • Loading branch information
wkleinheerenbrink authored Sep 11, 2023
1 parent 208df2c commit 200a44c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plugins/lookup/onepassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ def _parse_field(self, data_json, field_name, section_title=None):
# If the field name doesn't exist in the section, match on the value of "label"
# then "id" and return "value"
if field.get("label") == field_name:
return field["value"]
return field.get("value")

if field.get("id") == field_name:
return field["value"]
return field.get("value")

# Look at the section data and get an indentifier. The value of 'id' is either a unique ID
# or a human-readable string. If a 'label' field exists, prefer that since
Expand All @@ -475,10 +475,10 @@ def _parse_field(self, data_json, field_name, section_title=None):
if section_title == current_section_title:
# In the correct section. Check "label" then "id" for the desired field_name
if field.get("label") == field_name:
return field["value"]
return field.get("value")

if field.get("id") == field_name:
return field["value"]
return field.get("value")

return ""

Expand Down

0 comments on commit 200a44c

Please sign in to comment.