[wp-trac] [WordPress Trac] #46431: wp_unique_term_slug() doesn't guarantee unique slugs for child terms

WordPress Trac noreply at wordpress.org
Wed Mar 6 14:22:32 UTC 2019


#46431: wp_unique_term_slug() doesn't guarantee unique slugs for child terms
--------------------------+-----------------------------
 Reporter:  saskak        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  5.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Steps to reproduce:
 0. Create a fresh site with WP 5.1 and Twenty Nineteen
 1. Create a category "Animal" with slug "animal"
 2. Create a category "Dog" with slug "dog"
 3. Create a child category for "Animal" named "Cat" with slug "dog-animal"
 4. Create a top-level category "Giraffe" with slug "giraffe"
 5. Edit the "Giraffe" category so that in a single update, the parent
 changes from "None" to "Animal" and the slug becomes "dog".

 What I expected?
 The slug of category "Giraffe" should have become "dog-animal-2".

 What did I get?
 Category "Giraffe" now has identical slug with "Cat", both having the
 exact same slug "dog-animal".

 ---

 I tracked this down to `wp_unique_term_slug()`. It seems that if a parent
 suffix is added to a term, no further checks are made to ensure its
 uniqueness. The whole section where a number is appended is skipped.

 Why those exact steps are needed to reproduce this has to do with
 differences in `wp_insert_term()` and `wp_update_term()` I won't go into
 detail on that as it's a completely separate issue and seemingly a huge
 mess...

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46431>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list