Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/wp-admin/options-permalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,15 @@
}

if ( isset( $_POST['category_base'] ) ) {
$category_base = $_POST['category_base'];

if ( ! empty( $category_base ) ) {
$category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
}
$category_base = ltrim( $_POST['category_base'], '/' );
$category_base = empty( $category_base ) ? '' : $blog_prefix . '/' . implode( '/', array_map( 'sanitize_title_with_dashes', preg_split( '|/+|', $category_base ) ) );

$wp_rewrite->set_category_base( $category_base );
}

if ( isset( $_POST['tag_base'] ) ) {
$tag_base = $_POST['tag_base'];

if ( ! empty( $tag_base ) ) {
$tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
}
$tag_base = ltrim( $_POST['tag_base'], '/' );
$tag_base = empty( $tag_base ) ? '' : $blog_prefix . '/' . implode( '/', array_map( 'sanitize_title_with_dashes', preg_split( '|/+|', $tag_base ) ) );

$wp_rewrite->set_tag_base( $tag_base );
}
Expand Down
36 changes: 36 additions & 0 deletions tests/phpunit/tests/admin/optionsPermalink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Tests for wp-admin/options-permalink.php
*
* @group admin
* @group rewrite
*/
class Tests_Admin_OptionsPermalink extends WP_UnitTestCase {
/**
* Data provider for base sanitization tests.
*/
public function data_base_sanitization() {
return array(
array( 'Foo Bar', '/foo-bar' ),
array( 'Foo & Bar!', '/foo-bar' ),
array( 'Foo Bar/Baz Qux', '/foo-bar/baz-qux' ),
array( '', '' ),
array( '/Foo Bar', '/foo-bar' ),
array( 'Multiple/Slashes', '/multiple/slashes' ),
);
}

/**
* Test category and tag base sanitization.
*
* @ticket 16839
* @dataProvider data_base_sanitization
*/
public function test_base_sanitization( $input, $expected ) {
$base = ltrim( $input, '/' );
$result = empty( $base ) ? '' : '/' . implode( '/', array_map( 'sanitize_title_with_dashes', preg_split( '|/+|', $base ) ) );

$this->assertSame( $expected, $result );
}
}
Loading