Making WordPress.org

Opened 3 years ago

Closed 3 years ago

#5711 closed defect (bug) (fixed)

Anchor id not sanitized

Reported by: sebastienserre's profile sebastienserre Owned by: dd32's profile dd32
Milestone: Priority: normal
Component: Handbooks Keywords: needs-patch
Cc:

Description

Hello,

We have a problem in the French documentation team with the id in the doc title.
As you may know, in French we have specials characters which need to be sanitized before being used in an URL.

Example:
the page https://fr.wordpress.org/support/article/faq-troubleshooting/#indésirablesspams will produce the really ugly https://fr.wordpress.org/support/article/faq-troubleshooting/#ind%c3%a9sirablesspams

It should be great if the id used to create the HTML anchor should be sanitized thanks to sanitize_title().

Change History (11)

#2 in reply to: ↑ 1 @dd32
3 years ago

Replying to sebastienserre:

sanitize_title_with_dashes is doing what it's intended to, the problem is that it's expected to have accents removed/replaced prior to calling it.

The appropriate code would be sanitize_title_with_dashes( remove_accents( $title ) ) or potentially just sanitize_title( $title ) which does the same thing, but with a more filtered list of slug creation filters.

#3 @dd32
3 years ago

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

In 10920:

Handbooks/HelpHub: Replace accented characters before converting a title into a slug for use as page anchors.

Fixes #5711.

#5 @sebastienserre
3 years ago

Thank you @dd32 for the explanation and the correction.

#6 @sebastienserre
3 years ago

I wonder if sanitize_title() shouldn't be used as we can find as @papicx in the french doc: https://fr.wordpress.org/support/article/introduction-to-blogging/#les-slugs-d%e2%80%99articles

I think using sanitize_title() should solve this. What do you think @dd32 ?

#8 @sebastienserre
3 years ago

@audrasjb suggests us on French Slack: https://developer.wordpress.org/reference/functions/sanitize_file_name/ which cover non-breaking-spaces and double-quotes

#9 @audrasjb
3 years ago

remove_accents (or sanitize_title) doesn't handle curly apostrophes, so maybe it would be better to use sanitize_file_name (see this Core ticket https://core.trac.wordpress.org/ticket/50231).

Last edited 3 years ago by audrasjb (previous) (diff)

#10 @sebastienserre
3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Hello @dd32

Do you think, we could use sanitize_file_name ?

Many thanks

#11 @dd32
3 years ago

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

In 10945:

Handbooks/HelpHub: Replace accented characters before converting a title into a slug for use as page anchors. Take Two.

This time use sanitize_title() so that sanitize_title_with_dashes() gets called with save context rather than display which properly strips any remaining entities.

Follow up to [10920].
Fixes #5711.

Note: See TracTickets for help on using tickets.