Make WordPress Core

Opened 15 years ago

Last modified 7 weeks ago

#16230 new defect (bug)

Category slugs not cut at 200 characters as it should under some conditions

Reported by: paolal's profile paolal Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords: needs-patch needs-refresh
Focuses: Cc:

Description

When a category name is longer than 200 characters, it is cut to 200 and so is the slug automatically created upon category creation.

Now, if you edit the category name or slug afterwards, again trying to set a name longer than 200 characters it is cut again.

But, if you edit the name or slug and use a very long string like this one:

%d1%85%d1%80%d0%b0%d0%bd%d0%b0/%d1%80%d0%b5%d1%86%d0%b5%d0%bf%d1%82%d0%b8/%d0%b4%d0%b5%d1%81%d0%b5%d1%80%d1%82%d0%b8-%d1%80%d0%b5%d1%86%d0%b5%d0%bf%d1%82%d0%b8-%d1%85%d1%80%d0%b0%d0%bd%d0%b0/%d1%81%d0%bb%d0%b0%d0%b4%d0%ba%d0%b8%d1%88%d0%b8-%d0%b4%d0%b5%d1%81%d0%b5%d1%80%d1%82%d0%b8-%d1%80%d0%b5%d1%86%d0%b5%d0%bf%d1%82%d0%b8-%d1%85%d1%80%d0%b0%d0%bd%d0%b0-%d1%80%d0%b5%d1%86%d0%b5%d0%bf%d1%/

Then the slug ends up being longer than the 200 chars limit.

Now if on the Categories list dashboard page you have more categories than visible on one page, and the category you edited above is not on page 1, the page it is on will appear empty (while successive pages will be all right if they contain regular categories)

This has been reproduced on 3.1-RC2-17283

Attachments (2)

16230-Category-slug-length-fix.diff (629 bytes) - added by sachinrajcp123 7 months ago.
16230-category-slug-length-fix-v2.diff (855 bytes) - added by sachinrajcp123 7 weeks ago.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
15 years ago

A question aside: do we actually need to store slugs in urlencoded form? It only allows 66 chars for non-English slugs. It still should be enough for most cases, but is noticeably less than the original 200 characters limit.

Version 0, edited 15 years ago by SergeyBiryukov (next)

#2 @markjaquith
15 years ago

  • Milestone changed from Awaiting Review to Future Release

#3 @SergeyBiryukov
15 years ago

  • Keywords needs-patch added; category slug removed

Related: #10483

#4 @nacin
12 years ago

  • Component changed from General to Taxonomy

#5 @chriscct7
10 years ago

  • Keywords needs-testing added

Seems to still be a bug on 4.3.1

#6 @sachinrajcp123
7 months ago

Bug fix: Ensure category slugs are truncated to 200 characters before insertion to match expected limits.

#7 @huzaifaalmesbah
7 weeks ago

  • Keywords needs-refresh added; needs-testing removed

Patch Testing Report

Patch Tested:
https://core.trac.wordpress.org/attachment/ticket/16230/16230-Category-slug-length-fix.diff

Environment

  • WordPress: 7.0-alpha-61215-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 143.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Two 2.1
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.1

Steps taken

  1. Created multiple categories to ensure pagination in the Categories admin screen.
  2. Created a new category with a normal name.
  3. Edited the category slug and pasted a very long non-English string.
  4. Repeated the test using a very long URL-encoded string containing multiple path segments.
  5. Observed the saved slug length in the database and in the admin UI.
  6. Navigated to the Categories list page and paginated to the page containing the edited category.
  7. Applied the patch and repeated all steps.
  1. ❌ Patch is failing

Expected result

  • Category slugs should be truncated to a maximum of 200 characters regardless of input type.
  • Long non-English and URL-encoded slug values should not bypass the length limit.
  • The Categories admin list should not render empty pages when paginating.
Note: See TracTickets for help on using tickets.