-
Notifications
You must be signed in to change notification settings - Fork 3.4k
memoize wp_normalize_path #10770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memoize wp_normalize_path #10770
Changes from 5 commits
12fde07
8b21f23
0f68954
b16350b
9369fd0
9664f3b
9c85c8b
0d12856
3e306c2
c243205
1bb3064
8b9d7e1
49a4a73
39df60c
3188ab4
ca34f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,9 +222,50 @@ public function data_wp_normalize_path() { | |
| array( 'php://input', 'php://input' ), | ||
| array( 'http://example.com//path.ext', 'http://example.com/path.ext' ), | ||
| array( 'file://c:\\www\\path\\', 'file://C:/www/path/' ), | ||
|
|
||
| // Edge cases. | ||
| array( '', '' ), // Empty string should return empty string. | ||
| array( 123, '123' ), // Integer should be cast to string. | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_normalize_path() works with objects that have __toString(). | ||
| * | ||
| * This is important because the function uses a static cache, and the input | ||
| * must be cast to string before being used as an array key. | ||
| * | ||
| * @ticket 33265 | ||
|
josephscott marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public function test_wp_normalize_path_with_stringable_object() { | ||
| $stringable = new class() { | ||
| public function __toString() { | ||
| return '/var/www/html\\test'; | ||
| } | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a more representative test might be an SplFileInfo instance, since that is actually used in Core. as discovered in #10781 we can fix that currently-improper call in another patch.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no particular preference there. I will update the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
|
|
||
| $this->assertSame( '/var/www/html/test', wp_normalize_path( $stringable ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_normalize_path() returns consistent results on repeated calls. | ||
| * | ||
| * The function uses a static cache, so this verifies cache behavior. | ||
| * | ||
| * @ticket 33265 | ||
|
josephscott marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public function test_wp_normalize_path_returns_consistent_results() { | ||
| $path = 'C:\\www\\path\\'; | ||
|
|
||
| $first_call = wp_normalize_path( $path ); | ||
| $second_call = wp_normalize_path( $path ); | ||
| $third_call = wp_normalize_path( $path ); | ||
|
|
||
| $this->assertSame( $first_call, $second_call, 'Second call should return same result as first.' ); | ||
| $this->assertSame( $second_call, $third_call, 'Third call should return same result as second.' ); | ||
| $this->assertSame( 'C:/www/path/', $first_call, 'Normalized path should match expected value.' ); | ||
| } | ||
|
josephscott marked this conversation as resolved.
|
||
|
|
||
| public function test_wp_unique_filename() { | ||
|
|
||
| $testdir = DIR_TESTDATA . '/images/'; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.