Make WordPress Core

Opened 3 weeks ago

Last modified 2 weeks ago

#64284 new defect (bug)

Convert times/multiplication symbol (×) into the letter "x" when sanitizing titles for slugs

Reported by: archmaster7's profile archmaster7 Owned by:
Milestone: 7.0 Priority: normal
Severity: minor Version:
Component: Formatting Keywords: changes-requested has-patch needs-unit-tests
Focuses: Cc:

Description (last modified by westonruter)

We had an issue where user thought they were entering an x (Latin Small Letter X (U+0078)) but they were actually entering the multiplication symbol (Multiplication Sign (U+00D7)). An "x" did not show up in the slug which lead to some issues. Might suggest disallowing Multiplication Sign (U+00D7) from titles.

The multiplication symbol can be replaced with "x" automatically when sanitizing the title for use in a slug. Core does similarly for dashes which get replaced with hyphens via sanitize_title_with_dashes(). This was touched in the 6.9 release in #64089.

Attachments (1)

64284.diff (1.6 KB) - added by iflairwebtechnologies 2 weeks ago.

Download all attachments as: .zip

Change History (12)

#1 follow-up: @westonruter
3 weeks ago

Maybe the multiplication symbol should be replaced with "x" automatically in the slugs? We do this similarly for dashes which get replaced with hyphens. This was touched in the 6.9 release in #64089.

This could be tackled as part of #64151.

#2 in reply to: ↑ 1 @desrosj
3 weeks ago

  • Component changed from General to Formatting
  • Keywords needs-patch added

Replying to westonruter:

Maybe the multiplication symbol should be replaced with "x" automatically in the slugs? We do this similarly for dashes which get replaced with hyphens.

I think this makes sense, @westonruter.

Tackling it with #64151 could make sense, but that seems like a much larger effort that may take a while. Since this is just one character and a one line change (excluding tests), the best path forward may be to fix this now rather than wait.

#3 @westonruter
3 weeks ago

  • Milestone changed from Awaiting Review to 7.0

#4 @westonruter
3 weeks ago

  • Description modified (diff)
  • Summary changed from Disallow Multiplication Symbol in WordPress Titles to Convert times/multiplication symbol (×) into the letter "x" when sanitizing titles for slugs

#5 @iflairwebtechnologies
2 weeks ago

  • Keywords has-patch added; needs-patch removed
  • Version set to trunk

Hi
This patch resolves issue #64284, where the multiplication symbol (×) wasn't being replaced with the letter "x" when sanitizing titles for slugs.

The patch adds a line in the sanitize_title_with_dashes function to replace the multiplication sign (×) with "x" directly, as well as its encoded form (%c3%97).

Please review the patch and let me know if any changes are required.

#6 follow-up: @palak678
2 weeks ago

I tested this on 6.9 RC3 with PHP 8.4. The title cleanup works well now. The multiplication sign changes to a normal ‘x’ in the slug. This makes the slug function easier to understand and more consistent.

#7 in reply to: ↑ 6 @iflairwebtechnologies
2 weeks ago

Replying to palak678:

I tested this on 6.9 RC3 with PHP 8.4. The title cleanup works well now. The multiplication sign changes to a normal ‘x’ in the slug. This makes the slug function easier to understand and more consistent.

Are you asking whether the patch we created (64284.diff) is functioning correctly, or if any improvements are needed?

#8 @desrosj
2 weeks ago

  • Version trunk deleted

The Version field is for indicating the version of WordPress that first experienced a given problem.

Please leave the version as set unless you’ve discovered details that show it was introduced during a different release. Switching back to trunk since this was not introduced during the 6.9 release.

#9 @palak678
2 weeks ago

Replying to @iflairwebtechnologies

I tested this on 6.9 RC3 with PHP 8.4, and without applying the patch the multiplication sign is already converting to a normal ‘x’ in the slug. The functionality seems to be working.

Last edited 2 weeks ago by palak678 (previous) (diff)

#10 @westonruter
2 weeks ago

  • Keywords needs-patch added; has-patch removed

#11 @westonruter
2 weeks ago

  • Keywords changes-requested has-patch needs-unit-tests added; needs-patch removed

The patch 64284.diff seems to have unrelated changes.

Please open a pull request for collaboration and testing.

Also, I'm not entirely sure that sanitize_title_with_dashes() is the right function to apply this change in, since it is not related to replacing characters with dashes (read: hyphens). This is with discussing. That said, it actually does already replace some characters to 'x':

<?php
// Convert &times to 'x'.
$title = str_replace( '%c3%97', 'x', $title );

So this seems to be already settled.

The relevant addition from the patch then seems to be:

<?php
// Add the new line to convert the multiplication sign (×) directly to "x"
$title = str_replace( '×', 'x', $title );

Still, the patch replaces wp_is_valid_utf8() with seems_utf8() without explanation.

This will also need unit tests.

Note: See TracTickets for help on using tickets.