Closed Bug 1780436 Opened 2 years ago Closed 2 years ago

Review use of form.elements.namedItem() and form.children.namedItem()

Categories

(Toolkit :: Password Manager, task, P3)

task

Tracking

()

RESOLVED FIXED

People

(Reporter: serg, Assigned: issammani)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

satchel_common.js and pwmgr_common.js seems to be using similar logic to find element by name.

Both are using namedItem() which can also find element by id attribute. Both times we do an extra check to confirm we are not finding element by id.

The difference is that Satchel code is looking into form.elements and Password Manager is looking into form.children. .elements is semantically more appropriate and can find elements deep inside descendants, .children works only for the immediate children nodes. .elements does not work for "form-like <div>" though.

Both situations can be improved by using

.querySelector(`name="${name}"]`)

Also there is a comment:

Login Mananger happens to use .namedItem

Which does not seem to be true anymore, I couldn't find references to namedItem in password manager code.

Lets take the chance to fix tests to use querySelector and stop using confusing namedItem

Severity: -- → N/A
Priority: -- → P3
Assignee: nobody → imani
Status: NEW → ASSIGNED
Pushed by imani@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1240aec48a5f Use querySelector in getFormElementByName instead of namedItem. r=sgalich https://hg.mozilla.org/integration/autoland/rev/77711cf24acd Reuse getFormElementByName in password manager and remove usage of $_. r=sgalich
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: