Opened 9 years ago
Closed 8 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.
- Setup WP Unit Tests: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/
- 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 skippost_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)
Change History (10)
#1
@
9 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.
9 years ago
#3
@
9 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.
unit test file