Skip to content
Permalink
Browse files

Menus: Trim whitespace from custom link URLs.

Props majemedia, SergeyBiryukov.
Merges [45655] and [45656] to the 5.2 branch.
Fixes #47723.

git-svn-id: https://develop.svn.wordpress.org/branches/5.2@45832 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Aug 19, 2019
1 parent 29b5246 commit 361af8b2db522e4809c9f41141eecc833152f57f
Showing with 40 additions and 6 deletions.
  1. +9 −5 src/wp-includes/nav-menu.php
  2. +31 −1 tests/phpunit/tests/post/nav-menu.php
@@ -456,11 +456,15 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
$original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;
if ( 'custom' != $args['menu-item-type'] ) {
/* if non-custom menu item, then:
* use original object's URL
* blank default title to sync with original object's
*/
if ( 'custom' === $args['menu-item-type'] ) {
// If custom menu item, trim the URL.
$args['menu-item-url'] = trim( $args['menu-item-url'] );
} else {
/*
* If non-custom menu item, then:
* - use the original object's URL.
* - blank default title to sync with the original object's title.
*/
$args['menu-item-url'] = '';
@@ -149,7 +149,7 @@ function test_orphan_nav_menu_item() {
array(
'menu-item-type' => 'custom',
'menu-item-title' => 'Wordpress.org',
'menu-item-link' => 'http://wordpress.org',
'menu-item-url' => 'http://wordpress.org',
'menu-item-status' => 'publish',
)
);
@@ -926,4 +926,34 @@ function test_class_applied_to_privacy_policy_page_item() {
$this->assertContains( 'menu-item-privacy-policy', $classes );
}
/**
* @ticket 47723
* @dataProvider data_trim_url_for_custom_item
*/
function test_trim_url_for_custom_item( $custom_url, $correct_url ) {
$custom_item_id = wp_update_nav_menu_item(
$this->menu_id,
0,
array(
'menu-item-type' => 'custom',
'menu-item-title' => 'WordPress.org',
'menu-item-url' => $custom_url,
'menu-item-status' => 'publish',
)
);
$custom_item = wp_setup_nav_menu_item( get_post( $custom_item_id ) );
$this->assertEquals( $correct_url, $custom_item->url );
}
/**
* Provides data for test_trim_url_for_custom_item().
*/
function data_trim_url_for_custom_item() {
return array(
array( 'https://wordpress.org ', 'https://wordpress.org' ),
array( ' https://wordpress.org', 'https://wordpress.org' ),
);
}
}

0 comments on commit 361af8b

Please sign in to comment.
You can’t perform that action at this time.