WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#3683 closed defect (bug) (fixed)

It is possible to create multiple categories with the same name and same slug

Reported by: johnbillion Owned by: rob1n
Milestone: 2.3 Priority: normal
Severity: normal Version: 2.1
Component: Administration Keywords: dev-feedback 2nd-opinion
Focuses: Cc:

Description

This is a trivial one, I know.

It is possible to create multiple categories with the same name and/or same slug, and doing so breaks all concerned categories.

To recreate:

  1. Go to Manage -> Categories in the admin panel.
  1. Create a new category.
  1. Create another category with the same name and/or same slug.
  1. Place some posts into these categories (so they show up on the blog) and then attempt to browse one of the categories via the blog. A 404 Not Found error is returned on all categories concerned.

=================

Desired Behaviour:

Either the user is alerted that they are attempting to create a duplicate category, or the duplicate category is created with a numerical suffix on the slug (eg. articles-2) much the same as is done with multiple blog posts that have the same titles.

IMO the first option would be preferable.

Change History (16)

comment:1 johnbillion7 years ago

  • Severity changed from trivial to minor

comment:2 foolswisdom7 years ago

  • Milestone set to 2.1.1
  • Priority changed from lowest to high
  • Severity changed from minor to major

johnbillion, thank you for the excellent bug reports!

Raising severity because not supposed to be able to create duplicate categories.

comment:3 Nazgul7 years ago

  • Milestone changed from 2.1.1 to 2.1.2

2.1.1 is out, so bumping the milestone to 2.1.2.

comment:4 johnbillion7 years ago

Anyone have an opinion on the desired behaviour in this situation? It might spur someone on to write a patch if a decision about the desired behaviour is made. (I'd do it myself, alas I'm not familiar enough yet with WordPress.)

comment:5 rob1n7 years ago

  • Milestone changed from 2.1.3 to 2.2
  • Owner changed from anonymous to rob1n
  • Status changed from new to assigned

I'd say this should be fixed. It's expected behavior, and things go haywire if two categories have the same slugs.

But then again, why would you create categories with the same name and or slug? But then again, we should have a safeguard... never know what those pesky users can do >.<.

comment:6 rob1n7 years ago

Also, changing milestone to 2.2 as this isn't a critical fix.

comment:7 rob1n7 years ago

See also #1956. Though I don't think we should transparently change the URL -- we should change the slug in the first place.

comment:8 rob1n7 years ago

  • Keywords dev-feedback 2nd-opinion added; categories removed

comment:9 charleshooper7 years ago

+1 on alerting the user. I feel that if a user tries to create a category with a specific slug the user should be alerted instead of us just silently changing the slug.

However it might also make sense to have WP change the slug on its own and then alert the user that such a change was made.

comment:10 majelbstoat7 years ago

The post slug is silently changed if that clashes, so this wouldn't be all that unexpected.

comment:11 ryan7 years ago

Category hierarchies need to be taken into account. Two categories named "Bar" are different if the y have different parents. /bar is not /foo/bar.

comment:12 foolswisdom7 years ago

  • Milestone changed from 2.2 to 2.3

comment:13 jhodgdon7 years ago

As of [5243], the behavior has been changed (I think it actually changed in [5148]).

Currently, what happens is that if you try to add a category with the same slug as an existing category, the code treats it as an update on the original category. However, on the screen it still says "added category abc", which is incorrect since all that happened was it updated existing category abc.

But anyway it is now impossible to add a category with the same slug as an existing category. Same name is still possible, but shouldn't cause any major difficulties (I tested this and didn't see any problems).

In my opinion, however, the existing behavior is undesirable.

comment:14 rob1n7 years ago

  • Status changed from assigned to new

comment:15 rob1n7 years ago

  • Priority changed from high to normal
  • Severity changed from major to normal

comment:16 markjaquith7 years ago

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

It's now not possible to add a category with the same slug.

Note: See TracTickets for help on using tickets.