Opened 2 years ago

Closed 3 months ago

Last modified 3 months ago

#17562 closed enhancement (fixed)

esc_url() printed by the_permalink()

Reported by: mfields Owned by: nacin
Priority: normal Milestone: 3.6
Component: Template Version: 3.2
Severity: normal Keywords: has-patch 3.4-early
Cc: michael@…

Description

Using Mark Jaquith's rule of escaping output as late as possible, I believe that it would be correct to use esc_url() on the output of the_permalink. It may be helpful in correcting mistakes in plugins that use the "the_permalink" filter as well.

Attachments (1)

17562.the-permalink-escape-output.diff (471 bytes) - added by mfields 2 years ago.
Filter output of the_permalink() through esc_url() before printing.

Download all attachments as: .zip

Change History (10)

mfields2 years ago

Filter output of the_permalink() through esc_url() before printing.

  • Cc michael@… added

I can imagine this resulting in double-encoding in some cases.

I would be interested to learn more about these cases. I use this function pretty liberally in my projects and would love to know in which situations it would double encode.

This seems like the right thing to do to me as well. the_permalink() is a template function, so having output be escaped properly by default seems correct to me.

I don't believe it should lead to double-encoding issues.

esc_url() doesn't encode HTML entities beyond escaping level 1.

  • & - level 0
  • & - level 1
  • & - level 2
  • Keywords 3.4-early added; dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

In themes I've recently worked on, I've been adding add_filter( 'the_permalink', 'esc_url' );. This is a pretty obvious change. Let's add this in 3.4-early.

Ultimately, it will cause some issues, but it will be rare: A) htmlspecialchars() is used, rather than esc_url() or nothing, and B) the URL actually has something to be encoded, which is not particularly common at least regarding ampersands.

  • Milestone changed from Future Release to 3.6
  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 23527:

Automatically esc_url() the URL echoed by the_permalink().

This makes the_permalink() useful, rather than needing to do echo esc_url( get_permalink() ) to get proper encoding of ampersands, etc. This will not double-encode when esc_url() has already been applied to the filter here, but that code can now be removed.

props mfields.
fixes #17562.

In 23528:

esc_url() when printing a URL into an attribute, even when it is known to be safe. (see #17562)

Note: See TracTickets for help on using tickets.