WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#36174 closed defect (bug) (fixed)

Child posts of drafts get an extraneous slash in the permalink

Reported by: inderpreet99 Owned by: SergeyBiryukov
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Permalinks Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Problem
Calling get_post_permalink() on a published child post with draft parent (for a hierarchical post type) comes up as http://example.org/test//post-title-1/ rather than http://example.org/test/post-title-1/.

Reproduction
Reproduce bug by running the attached unit test test_draft_child_post_link.php within wp-unit-tests.

  1. Setup WP Unit Tests: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/
  2. Run phpunit test_draft_child_post_link.php

Log

wordpress-develop isingh$ phpunit test_draft_child_post_link.php
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 5.2.9 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 714 ms, Memory: 33.50Mb

There was 1 failure:

1) Test_Draft_Child_URL::test_draft_child_post_link
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://example.org/test/post-title-1/'
+'http://example.org/test//post-title-1/'

/Users/isingh/Dropbox/work/wordpress-develop/test_draft_child_post_link.php:27

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

Patch

  • Attached as patch_draft_child_post_link.diff.
  • Fix the get_page_uri() function with an extra conditional to skip post_name when empty.

Background

  • In the BU Navigation plugin unit tests, we have a test to generate a draft page and then a published child post. In the test, bu-navigation ends up generating a URL more correct (without the double slash), mostly due to the above patched check we have in a custom function.
  • This behavior was previously reported in #7915 when it was marked worksforme.

Attachments (2)

test_draft_child_post_link.php (839 bytes) - added by inderpreet99 4 years ago.
unit test file
patch_draft_child_post_link.diff (406 bytes) - added by inderpreet99 4 years ago.
patch

Download all attachments as: .zip

Change History (10)

@inderpreet99
4 years ago

unit test file

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Permalinks
  • Milestone changed from Awaiting Review to 4.5
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


4 years ago

#3 @johnbillion
4 years ago

  • Keywords has-patch has-unit-tests added
  • Version trunk deleted

It's worth noting that this problem only appears when the draft parent post does not have a slug.

This means if you publish a parent post, publish a child post of it, and then unpublish its parent, the issue does not appear because the draft parent will have a slug. Thus, it's difficult to reproduce in the admin area because the user needs to explicitly remove the parent post's slug when switching it back to draft.

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


4 years ago

This ticket was mentioned in Slack in #core by mike. View the logs.


4 years ago

#6 @mikeschroder
4 years ago

  • Milestone changed from 4.5 to Future Release

Per Slack, punting due to timing in cycle, but feel free to re-add/commit if you'd like to tackle this before RC, @SergeyBiryukov @johnbillion.

#7 @SergeyBiryukov
4 years ago

  • Milestone changed from Future Release to 4.6

#8 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38145:

Permalinks: In get_page_uri(), don't prepend a parent page slug if it's empty.

Props inderpreet99, SergeyBiryukov.
Fixes #36174.

Note: See TracTickets for help on using tickets.