Skip to content

Google Maps shortcode: fix %26 in place names causing 400 errorsFix: Google Maps shortcode fails when place name includes &#48266

Open
matticbot wants to merge 1 commit intotrunkfrom
ai/agent/tstaisb-11-1776952499
Open

Google Maps shortcode: fix %26 in place names causing 400 errorsFix: Google Maps shortcode fails when place name includes &#48266
matticbot wants to merge 1 commit intotrunkfrom
ai/agent/tstaisb-11-1776952499

Conversation

@matticbot
Copy link
Copy Markdown
Contributor

Fixes TSTAISB-11

Proposed changes

  • Fix [googlemaps] shortcode failing with a 400 error when a place name contains &.

Root cause: When the shortcode is processed, parse_str() URL-decodes %26 to a bare &. The previous code used esc_attr() to rebuild query parameters, which HTML-encodes & as &. When a browser fetches the iframe src, it HTML-decodes & back to &, which Google's API interprets as a query-parameter separator rather than part of the place name — resulting in a 400 error.

Fix: Replace esc_attr() in the URL reconstruction loop with rawurlencode() on the value. This re-encodes & as %26 (proper URL encoding). The esc_url() call at the end still handles HTML-safety for the src attribute.

Related product discussion/links

  • Linear: TSTAISB-11

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

No.

Testing instructions

  1. Go to Google Maps and copy the embed code for a location with & in the name (e.g. "The Westin Doha Hotel & Spa").
  2. Paste the <iframe> into a WordPress post (Block Editor).
  3. WordPress converts it to a [googlemaps ...] shortcode.
  4. Publish/preview — the map should render correctly (no 400 error).

Before: The embed fails with a 400 error because &amp; in the place name value is decoded by the browser to &, which Google treats as a query-parameter separator.

After: The embed renders correctly because %26 is preserved in the URL, and Google decodes it server-side to & as part of the place name.


This PR was auto-generated by AI Coder. Please review carefully before merging.

parse_str() decodes %26 (URL-encoded ampersand) to a bare &. The previous
code used esc_attr() to reconstruct query params, which HTML-encoded & to
&amp;. Browsers then decode &amp; back to &, which Google treats as a query
param separator rather than part of the place name, resulting in a 400 error.

Fix: use rawurlencode() on values so & is re-encoded as %26 (proper URL
encoding) instead of &amp; (HTML encoding). The final esc_url() call handles
HTML-safety of the complete URL for the iframe src attribute.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added [Feature] Shortcodes / Embeds [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Apr 23, 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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Apr 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

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 ai/agent/tstaisb-11-1776952499 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack ai/agent/tstaisb-11-1776952499

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

@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Shortcodes / Embeds [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant