[PR #7241/1beb38ce backport][stable-6] Use get(..) instead of [..] for safe lookup of value (Fixes #7240) (#7257)

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).

(cherry picked from commit 1beb38ceff)

Co-authored-by: Wouter Klein Heerenbrink <wouter@fluxility.com>
This commit is contained in:
patchback[bot] 2023-09-13 06:24:24 +00:00 committed by GitHub
commit 578df1b054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 4 deletions

View file

@ -451,10 +451,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
@ -464,10 +464,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 ""