~sircmpwn/himitsu-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH himitsu-firefox] content: ignore superfluous key pairs

Details
Message ID
<20240827200836.19650-1-alamica@protonmail.com>
DKIM signature
pass
Download raw message
Patch: +11 -9
The code assumed some pairs could be optional, but as far as i can tell
this can only be specified when querying the database. Now instead look
for the form with most matching keys.

It may make sense to limit the match count to at least two to avoid
filling a completely unrelated form, but it is possible to have a
single-input form, so hopefully the on-demand nature of auto-filling is
enough.
---
I still don't feel good about making no requirement on the number of
matches, but couldn't think of a universal solution. Any thoughts?

 content/content.js | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/content/content.js b/content/content.js
index 73b657d..07fe75c 100644
--- a/content/content.js
+++ b/content/content.js
@@ -16,6 +16,9 @@ function handleAutofill(msg) {
			return;
		};
		const input = findInput(form, pair.key);
		if (input === null) {
			return;
		}
		input.click();
		input.focus();
		input.value = pair.value;
@@ -30,26 +33,25 @@ function handleAutofill(msg) {

function findForm(key) {
	const forms = document.querySelectorAll("form");
	let bestForm = null;
	let bestHits = 0;
	for (let i = 0; i < forms.length; i++) {
		const form = forms[i];
		let valid = true;
		let hits = 0;
		key.map(pair => {
			if (pair.key === "proto" || pair.key === "host") {
				return;
			};
			if (pair.optional) {
				return;
			}
			const input = findInput(form, pair.key);
			if (input === null) {
				valid = false;
			if (input !== null) {
				hits++;
			}
		});
		if (valid) {
			return form;
		if (bestForm === null || hits > bestHits) {
			bestForm = form;
		}
	}
	return null;
	return bestForm;
}

function findInput(elem, key) {
-- 
2.46.0

[himitsu-firefox/patches/.build.yml] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D3QYSWPMPXJC.2AZAYBFQDEQG8@fra01>
In-Reply-To
<20240827200836.19650-1-alamica@protonmail.com> (view parent)
DKIM signature
missing
Download raw message
himitsu-firefox/patches/.build.yml: FAILED in 20s

[content: ignore superfluous key pairs][0] from [tiosgz][1]

[0]: https://lists.sr.ht/~sircmpwn/himitsu-devel/patches/54759
[1]: alamica@protonmail.com

✗ #1313082 FAILED himitsu-firefox/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/1313082
Reply to thread Export thread (mbox)