Skip to content

Fix loose comparisons against wordlists in wordcheck UI - #1711

Open
bpfoley wants to merge 1 commit into
DistributedProofreaders:masterfrom
bpfoley:wordcheck_ui_strict
Open

bpfoley wants to merge 1 commit into
DistributedProofreaders:masterfrom
bpfoley:wordcheck_ui_strict

Conversation

@bpfoley

@bpfoley bpfoley commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

PHP's loose checking means (eg) in_array("011", ["11", "pm"]) => true

As used, this causes incorrect matches (and frequency counts) for words in particular wordlists.

Just using in_array(strict: true) exposes the sideeffect of appending spaces to numeric strings (to make them appear non-numeric) to avoid array_multisort sorting numeric strings differently, so we have to trim the words_by_freq keys we get back to be able to strictly compare them against our wordlists.

Unfortunately, these changes can't be unit tested in its current form as all the UI code outputs using echo.

@bpfoley

bpfoley commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Sandbox here. https://www.pgdp.org/~bfoley/c.branch/wordcheck_ui_strict/

As an example project, try the ad-hoc word list for https://www.pgdp.org/~bfoley/c.branch/wordcheck_ui_strict/tools/project_manager/edit_project_word_lists.php?projectid=projectID467370f85ad51

If you add 011 and 11 to the adhoc list, you should see only 11 appearing in the results and being in the bad word list for the project.

PHP's loose checking means (eg) in_array("011", ["11", "pm"]) => true

As used, this causes incorrect matches (and frequency counts) for
words in particular wordlists.

Just using in_array(strict: true) exposes the sideeffect of appending
spaces to numeric strings (to make them appear non-numeric) to avoid
array_multisort sorting numeric strings differently, so we have
to trim the words_by_freq keys we get back to be able to strictly
compare them against our wordlists.

Unfortunately, these changes can't be unit tested in its current form
as all the UI code outputs using echo.
@bpfoley
bpfoley force-pushed the wordcheck_ui_strict branch from ad9561b to c1c149b Compare November 22, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants