WordPress.org

Make WordPress Core

Opened 17 months ago

Closed 17 months ago

Last modified 11 months ago

#50106 closed defect (bug) (duplicate)

`wp_parse_str` as used by `add_query_arg` breaks URLs with the same query var name used multiple times

Reported by: wpsmith Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Script Loader Keywords:
Focuses: Cc:

Description

wp_parse_str as used by add_query_arg breaks URLs with the same query var name used multiple times.

To reproduce the problem, just add this inside any theme or plugin:

<?php
add_action( 'wp_enqueue_scripts', 'my_google_fonts_enqueue_styles' );
function my_google_fonts_enqueue_styles() {
        wp_enqueue_style(
                'my-google-fonts-1234567890',
                'https://fonts.googleapis.com/css2?family=Alex+Brush&family=Open+Sans:wght@400;700;800&display=swap',
                [],
                '3.2.0'
        );
}

The resulting link tag will be:

<link rel='stylesheet' id='my-google-fonts-1234567890'  href='https://fonts.googleapis.com/css2?family=Open+Sans%3Awght%40400%3B700%3B800&#038;display=swap&#038;ver=3.2.0' media='all' />

The expected result is:

<link rel='stylesheet' id='my-google-fonts-1234567890'  href='https://fonts.googleapis.com/css2?family=Alex+Brush&family=Open+Sans%3Awght%40400%3B700%3B800&#038;display=swap&#038;ver=3.2.0' media='all' />

Change History (5)

#1 @wpsmith
17 months ago

IMHO, this is a problem with Google's interface and how they have implemented their style URLs using the same query parameter twice instead of using something like family[]=, but with so many WP users using Google Fonts, I believe this should be fixed.

#2 @ocean90
17 months ago

  • Milestone changed from Awaiting Review to Future Release
  • Version trunk deleted

Noting that wp_parse_str() is currently a simple wrapper for PHP's own parse_str() function. The behaviour we are seeing here is also documented in a user note.

Since we already have this wrapper we could include a possible fix there.

#3 @SergeyBiryukov
17 months ago

  • Component changed from Formatting to Script Loader
  • Keywords needs-patch removed
  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the report, we're already tracking this issue in #49742.

#4 @apedog
17 months ago

Change the last parameter '3.2.0' to null (not false - that will just add the WP version).
The 'ver' prameter is used for cache-busting resources hosted on your site. So it's irrelevant when linking to external resources.
ie. you shouldn't add the 'ver' parameter to any external sources anyway.

#5 @ocean90
11 months ago

#51552 was marked as a duplicate.

Note: See TracTickets for help on using tickets.