[wp-trac] [WordPress Trac] #64538: memoize wp_normalize_path

WordPress Trac noreply at wordpress.org
Mon Mar 30 22:14:02 UTC 2026


#64538: memoize wp_normalize_path
--------------------------------------+--------------------------
 Reporter:  josephscott               |       Owner:  dmsnell
     Type:  defect (bug)              |      Status:  reopened
 Priority:  normal                    |   Milestone:  7.0
Component:  General                   |     Version:  3.9
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------

Comment (by dmsnell):

 that’s odd @desrosj, and it’s interesting to see that the error message
 has no reverse solidus characters


 {{{
 Failed asserting that an array has the key '/var/www/cache-testsubdir'.
 }}}

 This //should// read

 {{{
 Failed asserting that an array has the key '/var/www/cache-test\subdir\'.
 }}}

 Now this could be a byproduct of display issues in the log files, but I
 wonder if it could be related to the platform in any way. The test is
 dubious, and perhaps I didn’t properly evaluate it in the original ticket,
 as what matters most is whether the path normalizes as expected; not
 whether a particular internal optimization runs.

 We could try applying this patch to get more info out of the test.

 {{{
 diff --git a/tests/phpunit/tests/functions.php
 b/tests/phpunit/tests/functions.php
 index b6080da780..585e30c0c0 100644
 --- a/tests/phpunit/tests/functions.php
 +++ b/tests/phpunit/tests/functions.php
 @@ -278,7 +278,21 @@ class Tests_Functions extends WP_UnitTestCase {
                 $static_vars = $reflection->getStaticVariables();

                 $this->assertArrayHasKey( 'cache', $static_vars, 'Static
 cache array should exist.' );
 -               $this->assertArrayHasKey( $path, $static_vars['cache'],
 'Cache should contain the normalized path.' );
 +
 +               $seen_keys = array_keys( $static_vars['cache'] );
 +               $seen_keys = array_map(
 +                       static function ( $key ) {
 +                               return "'{$key}'";
 +                       },
 +                       $seen_keys
 +               );
 +               $seen_keys = empty( $seen_keys ) ? '(no cached keys)' :
 implode( ', ', $seen_keys );
 +               $this->assertArrayHasKey(
 +                       $path,
 +                       $static_vars['cache'],
 +                       "Path missing from cache: {$seen_keys}."
 +               );
 +
                 $this->assertSame( $expected, $static_vars['cache'][ $path
 ], 'Cached value should match the expected normalized path.' );
         }

 }}}

 cc: @josephscott

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


More information about the wp-trac mailing list