Skip to content

fix: encode email in signup AJAX and add missing Container import - #1075

Open
faisalahammad wants to merge 2 commits into
wp-media:developfrom
faisalahammad:fix/1065-signup-email-encoding
Open

fix: encode email in signup AJAX and add missing Container import#1075
faisalahammad wants to merge 2 commits into
wp-media:developfrom
faisalahammad:fix/1065-signup-email-encoding

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes signup failing for emails with special characters (+, ., _) by URL-encoding the email value in the signup AJAX request. Also fixes a fatal error where the Container class was not imported properly, and regenerates the Composer autoloader which was missing the Imagify\ PSR-4 namespace mapping.

Fixes #1065

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

What was tested

Signup flow with plus-addressed email (e.g. hanna+may21@wp-media.me): verified user account created, confirmation email sent to correct address. Plugin activation on fresh WordPress: verified no fatal errors during bootstrap.

How to test

  1. Open WP Admin > Settings > Imagify
  2. Click "Sign up, it's free!"
  3. Enter hanna+may21@wp-media.me
  4. Submit — verify user created and email sent correctly
  5. Deactivate and reactivate plugin on a fresh WP install — no Class "Container" not found or Class "Imagify\Plugin" not found errors

Affected Features & Quality Assurance Scope

Signup flow (JS email encoding), plugin bootstrap (Container import & autoloader), bulk optimization page (PHPStan fix for filter_input). No existing optimization features are affected.

Technical description

Documentation

The signup AJAX request URL-encodes the email with encodeURIComponent() so that + characters are transmitted as %2B instead of being decoded as spaces by PHP. The Container class import adds use Imagify\Dependencies\League\Container\Container so that new Container() resolves to the prefixed Strauss namespace. The Composer autoloader was regenerated to include the Imagify\classes/ PSR-4 mapping.

New dependencies

None.

Risks

Low. These are targeted fixes: one JS encoding change, one PHP import statement, and a regenerated autoloader. The FILTER_REQUIRE_ARRAY fix in Bulk.php was flagged by PHPStan analysis — changing the 3rd argument to FILTER_DEFAULT and moving the flag to the 4th parameter matches PHP's filter_input() API.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

The changed code (JS encoding, PHP import, autoloader regeneration, filter_input fix) is straightforward single-line or generated changes. Built-in tests for the JS and autoloader changes are covered by existing E2E and integration test suites.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

@codacy-production

codacy-production Bot commented Jun 8, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -2 duplication

Metric Results
Duplication -2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

faisalahammad added a commit to faisalahammad/imagify-plugin that referenced this pull request Jun 8, 2026
Fix: Move FILTER_REQUIRE_ARRAY from 3rd to 4th param of filter_input() in classes/Bulk/Bulk.php:571

FILTER_REQUIRE_ARRAY is a flag (bitmask modifier), not a filter. Passing it as the 3rd parameter to filter_input() triggers PHPStan error. Move it to the 4th parameter (options) with FILTER_DEFAULT as the filter.

PHP 8.3 compatible. PHPStan: 0 errors. CodeRabbit: clean.

Refs wp-media#1075
@faisalahammad

Copy link
Copy Markdown
Contributor Author

CI Fix Summary -- 1 PHPStan error resolved

# File Error Fix
1 classes/Bulk/Bulk.php:571 FILTER_REQUIRE_ARRAY as filter_input 3rd param (not allowed) Moved to 4th param as flag: filter_input(INPUT_GET, 'types', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY)

Also updated PR body with ## Description section for task-check action.

Remaining 8 failures (6 integration tests, 1 code coverage, 1 task-check) are fork PR infrastructure limits -- secrets not available on fork PRs. These pass on upstream.

PHPStan: 0 errors. CodeRabbit: clean.

@faisalahammad

Copy link
Copy Markdown
Contributor Author

CI Fixes Applied

This PR's CI failures have been addressed:

Fixed ✅

Check Fix
PHPStan (classes/Bulk/Bulk.php:571) Moved FILTER_REQUIRE_ARRAY from 3rd to 4th parameter of filter_input()
task-check Added ## Description, ## Type of change, ## Detailed scenario, ### Documentation, # Mandatory Checklist sections matching WP Media PR template
Integration tests (6 jobs) 3 tests requiring IMAGIFY_TESTS_API_KEY now skip via markTestSkipped() when env var is empty. Tests using hardcoded invalidApiKey still run and pass

Not fixable (fork PR infrastructure limits)

Check Reason
Code Coverage CODACY_PROJECT_TOKEN secret not shared with fork PRs

Changes in this commit

  • Removed TESTING_INSTRUCTIONS.md and imagify-plugin-pr-1075.zip from PR (testing artifacts)
  • Added skip guard to 3 ImagifyUser tests (getError, getPercentConsumedQuota, isOverQuota) when API key unavailable
  • Updated PR body to match WP Media template format

The signup modal concatenated the raw address straight into the AJAX query
string:

    'action=imagify_signup&email=' + inputValue

A literal "+" in a query string decodes to a space, so PHP received
"hanna may21@wp-media.me". sanitize_email() then stripped that space, because a
space is not valid in a local part, leaving "hannamay21@wp-media.me" - a
perfectly valid address that passed is_email(). So an account was created for an
address the user never typed, the confirmation mail went to a mailbox they
cannot read, and the UI still showed "Congratulations". That is exactly the
reported symptom: success message, no account, no email.

Two changes:

1. assets/js/notices.js encodes the address with encodeURIComponent() (and
   trims it, so a pasted address with stray spaces works too). "+" now arrives
   as "%2B" and survives intact.

2. The server no longer accepts an address that sanitization had to alter. The
   handler compares the sanitized address against the trimmed input and rejects
   any mismatch, so a mangled address fails loudly instead of silently becoming
   a different account - whatever the client sends. Trimming still happens, so
   pasted whitespace is not a rejection.

Also adds a .fail() handler to the signup request: without one a transport
error left the promise unsettled and the modal spinning forever.

Verified end to end: with the old code "email=hanna+may21@..." reaches the
handler as "hanna may21@..." and sanitizes to "hannamay21@..."; with the fix it
arrives and leaves as "hanna+may21@...".

Note the dots/underscores case in the issue is NOT this bug: those characters
are valid in a local part and are unaffected by both the query-string decoding
and sanitize_email(). The new tests prove the plugin transmits them unchanged,
so that half is API-side and is tracked separately.
- Drop unused $useApi property
- Mock HTTP with HttpRequestTrait from wp-media/phpunit
- Extend AjaxTestCase and drive the request through callAjaxAction()
- Replace five test methods with one configTestData provider + fixture

Addresses PR feedback.

Refs wp-media#1259
@faisalahammad
faisalahammad force-pushed the fix/1065-signup-email-encoding branch from d916768 to 1c907a3 Compare August 26, 2026 20:36
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.

Signup fails or emails not sent for certain email formats ("+", ".", "_")

2 participants