Skip to content

Commit fa2320b

Browse files
committed
Improve sanitize_slug
1 parent 0a69bf6 commit fa2320b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

php/class-assets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Assets extends Settings_Component {
117117
*/
118118
public function __construct( Plugin $plugin ) {
119119
parent::__construct( $plugin );
120+
$this->should_sanitize_slugs = true;
120121

121122
$this->media = $plugin->get_component( 'media' );
122123
$this->delivery = $plugin->get_component( 'delivery' );

php/traits/trait-params.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ trait Params_Trait {
3030
*/
3131
public $separator = '.';
3232

33+
/**
34+
* Whether to sanitize slugs.
35+
*
36+
* @var boolean
37+
*/
38+
protected $should_sanitize_slugs = false;
39+
3340
/**
3441
* Sets the params recursively.
3542
*
@@ -77,7 +84,6 @@ protected function set_param_array( $parts, $param, $value ) {
7784
* @return $this
7885
*/
7986
public function set_param( $param, $value = null ) {
80-
8187
$sanitized_param = $this->sanitize_slug( $param );
8288
$parts = explode( $this->separator, $sanitized_param );
8389
$param = array_shift( $parts );
@@ -140,6 +146,9 @@ public function remove_param( $param ) {
140146
* @return string
141147
*/
142148
protected function sanitize_slug( $slug ) {
149+
if ( ! $this->should_sanitize_slugs || ! str_contains( $slug, $this->separator ) ) {
150+
return $slug;
151+
}
143152

144153
$sanitized = array_map( 'sanitize_file_name', explode( $this->separator, $slug ) );
145154

0 commit comments

Comments
 (0)