Conversation
parse_str() decodes %26 (URL-encoded ampersand) to a bare &. The previous code used esc_attr() to reconstruct query params, which HTML-encoded & to &. Browsers then decode & 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 & (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>
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryThis 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. 🤷 |
Fixes TSTAISB-11
Proposed changes
[googlemaps]shortcode failing with a 400 error when a place name contains&.Root cause: When the shortcode is processed,
parse_str()URL-decodes%26to a bare&. The previous code usedesc_attr()to rebuild query parameters, which HTML-encodes&as&. When a browser fetches the iframesrc, 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 withrawurlencode()on the value. This re-encodes&as%26(proper URL encoding). Theesc_url()call at the end still handles HTML-safety for thesrcattribute.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
&in the name (e.g. "The Westin Doha Hotel & Spa").<iframe>into a WordPress post (Block Editor).[googlemaps ...]shortcode.Before: The embed fails with a 400 error because
&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
%26is preserved in the URL, and Google decodes it server-side to&as part of the place name.