Skip to content

Commit 4808feb

Browse files
committed
Fix appending args to script/style URLs
1 parent 71ea571 commit 4808feb

File tree

4 files changed

+73
-48
lines changed

4 files changed

+73
-48
lines changed

src/wp-includes/class-wp-scripts.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ class WP_Scripts extends WP_Dependencies {
2222
* Full URL with trailing slash.
2323
*
2424
* @since 2.6.0
25-
* @var string
25+
* @see wp_default_scripts()
26+
* @var string|null
2627
*/
2728
public $base_url;
2829

2930
/**
3031
* URL of the content directory.
3132
*
3233
* @since 2.8.0
33-
* @var string
34+
* @see wp_default_scripts()
35+
* @var string|null
3436
*/
3537
public $content_url;
3638

3739
/**
3840
* Default version string for scripts.
3941
*
4042
* @since 2.6.0
41-
* @var string
43+
* @see wp_default_scripts()
44+
* @var string|null
4245
*/
4346
public $default_version;
4447

@@ -118,6 +121,7 @@ class WP_Scripts extends WP_Dependencies {
118121
* List of default directories.
119122
*
120123
* @since 2.8.0
124+
* @see wp_default_scripts()
121125
* @var string[]|null
122126
*/
123127
public $default_dirs;
@@ -414,16 +418,18 @@ public function do_item( $handle, $group = false ) {
414418
}
415419

416420
$query_args = array();
417-
if ( null !== $obj->ver ) {
418-
$query_args['ver'] = false === $obj->ver ? $this->default_version : $obj->ver;
421+
if ( false === $obj->ver && is_string( $this->default_version ) ) {
422+
$query_args['ver'] = $this->default_version;
423+
} elseif ( is_scalar( $obj->ver ) ) {
424+
$query_args['ver'] = (string) $obj->ver;
419425
}
420426
if ( isset( $this->args[ $handle ] ) ) {
421427
parse_str( $this->args[ $handle ], $parsed_args );
422428
if ( $parsed_args ) {
423429
$query_args = array_merge( $query_args, $parsed_args );
424430
}
425431
}
426-
$src = add_query_arg( $query_args, $src );
432+
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
427433

428434
/** This filter is documented in wp-includes/class-wp-scripts.php */
429435
$src = esc_url_raw( apply_filters( 'script_loader_src', $src, $handle ) );

src/wp-includes/class-wp-styles.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,34 @@ class WP_Styles extends WP_Dependencies {
2222
* Full URL with trailing slash.
2323
*
2424
* @since 2.6.0
25-
* @var string
25+
* @see wp_default_styles()
26+
* @var string|null
2627
*/
2728
public $base_url;
2829

2930
/**
3031
* URL of the content directory.
3132
*
3233
* @since 2.8.0
33-
* @var string
34+
* @see wp_default_styles()
35+
* @var string|null
3436
*/
3537
public $content_url;
3638

3739
/**
3840
* Default version string for stylesheets.
3941
*
4042
* @since 2.6.0
41-
* @var string
43+
* @see wp_default_styles()
44+
* @var string|null
4245
*/
4346
public $default_version;
4447

4548
/**
4649
* The current text direction.
4750
*
4851
* @since 2.6.0
52+
* @see wp_default_styles()
4953
* @var string
5054
*/
5155
public $text_direction = 'ltr';
@@ -96,6 +100,7 @@ class WP_Styles extends WP_Dependencies {
96100
* List of default directories.
97101
*
98102
* @since 2.8.0
103+
* @see wp_default_styles()
99104
* @var string[]|null
100105
*/
101106
public $default_dirs;
@@ -212,7 +217,7 @@ public function do_item( $handle, $group = false ) {
212217
return true;
213218
}
214219

215-
$href = $this->_css_href( $src, $ver, $handle );
220+
$href = $this->_css_href( $src, $obj->ver, $handle );
216221
if ( ! $href ) {
217222
return true;
218223
}
@@ -419,19 +424,29 @@ public function all_deps( $handles, $recursion = false, $group = false ) {
419424
*
420425
* @since 2.6.0
421426
*
422-
* @param string $src The source of the enqueued style.
423-
* @param string $ver The version of the enqueued style.
424-
* @param string $handle The style's registered handle.
427+
* @param string $src The source of the enqueued style.
428+
* @param string|false|null $ver The version of the enqueued style.
429+
* @param string $handle The style's registered handle.
425430
* @return string Style's fully-qualified URL.
426431
*/
427432
public function _css_href( $src, $ver, $handle ) {
428433
if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) {
429434
$src = $this->base_url . $src;
430435
}
431436

432-
if ( ! empty( $ver ) ) {
433-
$src = add_query_arg( 'ver', $ver, $src );
437+
$query_args = array();
438+
if ( false === $ver && is_string( $this->default_version ) ) {
439+
$query_args['ver'] = $this->default_version;
440+
} elseif ( is_scalar( $ver ) ) {
441+
$query_args['ver'] = (string) $ver;
442+
}
443+
if ( isset( $this->args[ $handle ] ) ) {
444+
parse_str( $this->args[ $handle ], $parsed_args );
445+
if ( $parsed_args ) {
446+
$query_args = array_merge( $query_args, $parsed_args );
447+
}
434448
}
449+
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
435450

436451
/**
437452
* Filters an enqueued style's fully-qualified URL.

0 commit comments

Comments
 (0)