Skip to content

Search: fix uncaught URIError from malformed query params crashing Instant Search#50806

Open
interlineae wants to merge 2 commits into
trunkfrom
fix/instant-search-malformed-query-param
Open

Search: fix uncaught URIError from malformed query params crashing Instant Search#50806
interlineae wants to merge 2 commits into
trunkfrom
fix/instant-search-malformed-query-param

Conversation

@interlineae

@interlineae interlineae commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #50709

Proposed changes

  • Guard decodeURIComponent() in Instant Search's vendored query-string decoder (query-string-decode.js) against malformed percent-encoding (e.g. a stray %, an unresolved email merge tag like %DONOR%, or invalid escapes like %zz), which previously threw an uncaught URIError on every page load and crashed Instant Search's initialization, leaving the page blank.
  • Malformed sequences are sanitized (a bare % not starting a valid %XX escape is escaped to %25) and then decoded, so the value is recovered as literal plain text (e.g. %DONOR% decodes to the literal string %DONOR%) instead of throwing. This lets Instant Search keep treating the value as an active search term (e.g. showing its own "No results found" state) rather than silently dropping it or falling back to the site's classic search page.
  • In the rare residual case of a value that's well-formed %XX escapes but decodes to an invalid byte sequence (e.g. a truncated UTF-8 sequence), that key is dropped rather than kept as a raw value — keeping a still-encoded raw string would get double-encoded (and corrupted) the next time the query object is round-tripped through qss's encode().

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • On a site with Jetpack Search active and the Instant Search (overlay) experience enabled, visit a URL with a malformed query param typed directly in the address bar (not submitted via a form, which would properly encode it), e.g.:
    • https://yoursite.com/?s=%MA
    • https://yoursite.com/?s=%zz
    • https://yoursite.com/?test=%MALFORMED%
  • Before this fix: the page renders blank, and the console shows an uncaught URIError: URI malformed.
  • After this fix: the page renders normally. For a malformed s (search term) param, the Instant Search overlay opens showing "No results found" for the literal text (e.g. %MA). For a malformed bystander param unrelated to search, the page loads normally and that param is otherwise unaffected.
  • Run the JS test suite: pnpm test-scripts (from projects/packages/search/) — includes new regression tests in src/instant-search/external/test/query-string-decode.test.js.

@interlineae interlineae added the [Status] Needs Review This PR is ready for review. label Jul 24, 2026
@interlineae interlineae self-assigned this Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/instant-search-malformed-query-param branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/instant-search-malformed-query-param

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@interlineae
interlineae requested review from kangzj and robfelty July 24, 2026 13:28
@github-actions github-actions Bot added [Package] Search Contains core Search functionality for Jetpack and Search plugins [Tests] Includes Tests labels Jul 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Jul 24, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/instant-search/external/query-string-decode.js 18/21 (85.71%) 54.14% -10 💚

Full summary · PHP report · JS report

robfelty
robfelty previously approved these changes Jul 24, 2026

@robfelty robfelty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with one change. I don't think we should try to do the bare % replacement, because it results in confusing behavior, where it works sometimes and not others, in a way that is likely to make debugging more difficult in the future. I think catching the error is sufficient.

Comment thread projects/packages/search/src/instant-search/external/query-string-decode.js Outdated
… failure

Per review feedback (#50806): partial-recovery via a bare-% sanitization
regex was inconsistent and hard to debug — a merge tag like %ABTEST%
would still throw (A and B look like hex digits) while %DONOR% would
recover fine, depending on incidental letter content.

Instead, any value that fails to decode now uniformly falls back to an
empty string, regardless of what follows the %. This is already a
normal, well-supported state (the same as a user clearing the search
box), keeps the key present in the query object so a malformed search
term still registers as an active query, and is always safe to
re-encode later.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Search Contains core Search functionality for Jetpack and Search plugins [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Jetpack Search] Malformed query param value throws uncaught URIError and blanks the page

2 participants