[wp-trac] [WordPress Trac] #16859: esc_url eats square brackets.

WordPress Trac noreply at wordpress.org
Tue Sep 29 00:31:26 UTC 2015


#16859: esc_url eats square brackets.
--------------------------+--------------------------
 Reporter:  f00f          |       Owner:  johnbillion
     Type:  defect (bug)  |      Status:  accepted
 Priority:  normal        |   Milestone:  4.4
Component:  Formatting    |     Version:  3.1
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+--------------------------
Changes (by johnbillion):

 * keywords:  has-patch dev-feedback => has-patch


Comment:

 I was concerned about the performance of all the `preg_replace()` calls in
 [attachment:16859-03.2.patch] so I ran a bunch of benchmarks on 10,000
 iterations of `esc_url()`. It increases the processing time by around 40%.
 Critically, it doesn't pass a bunch of unit tests that I've just added.

 [attachment:16859.diff] tackles this slightly differently. Instead of
 parsing the URL into segments, individually escaping each segment, and
 then re-constructing the URL, it splits out the "front" of the URL
 (everything up to the domain and port), and only escapes square brackets
 in the remainder of the URL. It performs a fast `strpos()` comparison to
 see if the URL contains a square bracket, which adds almost no overhead to
 URLs with no square brackets, and an overhead of around 15% to URLs that
 do.

 I'm going to commit this and let the Travis tests run to see if anything
 else breaks.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/16859#comment:37>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list