avoid potentiall null hints in autofill (#2488)

This commit is contained in:
Philipp Crocoll
2024-01-02 16:26:02 +01:00
parent 2e9400cf4d
commit f4b5eee171

View File

@@ -434,7 +434,7 @@ namespace Kp2aAutofillParser
public static List<string> ConvertToCanonicalLowerCaseHints(string[] supportedHints) public static List<string> ConvertToCanonicalLowerCaseHints(string[] supportedHints)
{ {
List<string> result = new List<string>(); List<string> result = new List<string>();
foreach (string hint in supportedHints) foreach (string hint in supportedHints.Where(h => h != null))
{ {
var canonicalHint = ToCanonicalHint(hint); var canonicalHint = ToCanonicalHint(hint);
result.Add(canonicalHint.ToLower()); result.Add(canonicalHint.ToLower());
@@ -829,7 +829,7 @@ namespace Kp2aAutofillParser
// * if there is no such autofill hint, we use IsPassword to // * if there is no such autofill hint, we use IsPassword to
HashSet<string> autofillHintsOfAllFields = autofillView.InputFields.Where(f => f.AutofillHints != null) HashSet<string> autofillHintsOfAllFields = autofillView.InputFields.Where(f => f.AutofillHints != null)
.SelectMany(f => f.AutofillHints).Select(AutofillHintsHelper.ToCanonicalHint).ToHashSet(); .SelectMany(f => f.AutofillHints).Where(x => x != null).Select(AutofillHintsHelper.ToCanonicalHint).ToHashSet();
bool hasLoginAutofillHints = autofillHintsOfAllFields.Intersect(_autofillHintsForLogin).Any(); bool hasLoginAutofillHints = autofillHintsOfAllFields.Intersect(_autofillHintsForLogin).Any();
if (hasLoginAutofillHints) if (hasLoginAutofillHints)
@@ -839,9 +839,9 @@ namespace Kp2aAutofillParser
string[] viewHints = viewNode.AutofillHints; string[] viewHints = viewNode.AutofillHints;
if (viewHints == null) if (viewHints == null)
continue; continue;
if (viewHints.Select(AutofillHintsHelper.ToCanonicalHint).Intersect(_autofillHintsForLogin).Any()) if (viewHints.Where(h => h != null).Select(AutofillHintsHelper.ToCanonicalHint).Intersect(_autofillHintsForLogin).Any())
{ {
AddFieldToHintMap(viewNode, viewHints.Select(AutofillHintsHelper.ToCanonicalHint).ToHashSet().ToArray()); AddFieldToHintMap(viewNode, viewHints.Where(h => h != null).Select(AutofillHintsHelper.ToCanonicalHint).ToHashSet().ToArray());
} }
} }