mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-04 05:04:22 -07:00
[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:
parent
0b494a5d2d
commit
578df1b054
5 changed files with 118 additions and 4 deletions
|
@ -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 ""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue