Skip to content

Google Map: use wp_validate_redirect() for the search form action - #774

Closed
obenland wants to merge 1 commit into
trunkfrom
google-map/form-action-validation
Closed

obenland wants to merge 1 commit into
trunkfrom
google-map/form-action-validation

Conversation

@obenland

Copy link
Copy Markdown
Member

Follow-up to #773.

That PR added an is_network_url() helper to keep searchFormAction from pointing the search form off-site. Core already has a function for the same question — wp_validate_redirect() — so this swaps the helper out for it:

$attributes['searchFormAction'] = wp_validate_redirect( (string) ( $attributes['searchFormAction'] ?? '' ), '' );

It returns the fallback for anything that doesn't resolve to this site, which also makes the sanitize_url() call redundant — wp_sanitize_redirect() and the http/https scheme check are built in. Net: 45 lines removed, and two checks gained that the helper didn't have (malformed user/pass/host components, and control-character stripping).

Behavior

Every case in the existing rejection data provider still resolves to '', verified against the test environment: data:, vbscript:, mixed-case javascript:, off-site https, protocol-relative, escaped slashes, suffix lookalike, userinfo, https:///, https:////, and https:/.

Two inputs that used to be kept now fall back to live search, because core matches the host exactly:

  • a sibling subdomain (https://sub.example.org/events/)
  • a differently cased host (https://EXAMPLE.ORG/events/)

Both are safe destinations, so this is a narrowing, not a fix. It looks acceptable: no template in wporg-main-2022 or wporg-events-2023 sets searchFormAction at all, and the README already defines the intended value as "a page that has this block in the post content" — i.e. this site. Tests moved to cover the new behavior rather than the old.

A bare relative path like events/ also now resolves against REQUEST_URI instead of being passed through, which is only reachable if someone writes the attribute that way; the README points at page URLs.

Testing

  • npm run test:php — 46 tests, 117 assertions, green.
  • phpcs is clean on the changed lines. (The vendored PHPCompatibility sniff aborts locally on every file in the repo, including untouched ones, so that ran with the rest of the repo ruleset.)

🤖 Generated with Claude Code

`render()` ran `searchFormAction` through a local `is_network_url()` helper.
Core covers the same ground in `wp_validate_redirect()`, which returns the
fallback for anything that doesn't resolve to this site, so the helper and the
`sanitize_url()` call feeding it can both go.

One difference worth noting: core matches the host exactly, so a sibling
subdomain or a differently cased spelling of this host now falls back to live
search rather than being kept. Nothing in the templates sets the attribute, and
the README already describes it as a page on this site.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 15, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@obenland obenland closed this Sep 15, 2026
@obenland
obenland deleted the google-map/form-action-validation branch September 15, 2026 15:42
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