Use get(..) instead of [..] for safe lookup of value (Fixes #7240) (#7241)

A OnePassword field item might not have a value (property) when the user has omitted it (on purpose).
This commit is contained in:
Wouter Klein Heerenbrink 2023-09-13 07:48:36 +02:00 committed by GitHub
commit 1beb38ceff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 4 deletions

View file

@ -462,10 +462,10 @@ class OnePassCLIv2(OnePassCLIBase):
# 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
@ -475,10 +475,10 @@ class OnePassCLIv2(OnePassCLIBase):
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 ""