Repository navigation
Performance: Follow-up fixes to prepend_to_selector() optimization. #79499
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/12306 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/76556 | ||
| * https://github.com/WordPress/gutenberg/pull/79499 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| <?php | ||
| /** | ||
| * Tests selector list helpers in WP_Theme_JSON_Gutenberg. | ||
| * | ||
| * @package gutenberg | ||
| * | ||
| * @covers WP_Theme_JSON_Gutenberg | ||
| */ | ||
|
|
||
| class WP_Theme_JSON_Gutenberg_Selector_List_Test extends WP_UnitTestCase { | ||
| /** | ||
| * Invokes a protected static method on WP_Theme_JSON_Gutenberg. | ||
| * | ||
| * @param string $method_name Method name. | ||
| * @param mixed ...$args Method arguments. | ||
| * @return mixed Method result. | ||
| */ | ||
| private static function invoke_theme_json_method( $method_name, ...$args ) { | ||
| $theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' ); | ||
|
|
||
| $method = $theme_json->getMethod( $method_name ); | ||
| if ( PHP_VERSION_ID < 80100 ) { | ||
| $method->setAccessible( true ); | ||
| } | ||
|
|
||
| return $method->invokeArgs( null, $args ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider data_split_selector_list | ||
| * | ||
| * @param string $selector CSS selector list. | ||
| * @param string[] $expected Expected selectors. | ||
| */ | ||
| public function test_split_selector_list( $selector, $expected ) { | ||
| $this->assertSame( | ||
| $expected, | ||
| self::invoke_theme_json_method( 'split_selector_list', $selector ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, array{selector: string, expected: string[]}> | ||
| */ | ||
| public function data_split_selector_list() { | ||
| return array( | ||
| 'simple selector list' => array( | ||
| 'selector' => 'h1,h2', | ||
| 'expected' => array( 'h1', 'h2' ), | ||
| ), | ||
| 'preserves whitespace around selectors' => array( | ||
| 'selector' => '.a , .b , .c', | ||
| 'expected' => array( '.a ', ' .b ', ' .c' ), | ||
| ), | ||
| 'selector function list argument' => array( | ||
| 'selector' => ':where(.a, .b),.c', | ||
| 'expected' => array( ':where(.a, .b)', '.c' ), | ||
| ), | ||
| 'nested selector functions' => array( | ||
| 'selector' => ':where(:not(.a, .b), .c),.d', | ||
| 'expected' => array( ':where(:not(.a, .b), .c)', '.d' ), | ||
| ), | ||
| 'attribute string containing comma' => array( | ||
| 'selector' => '[data-label="Save, continue"],.fallback', | ||
| 'expected' => array( '[data-label="Save, continue"]', '.fallback' ), | ||
| ), | ||
| 'escaped comma in identifier' => array( | ||
| 'selector' => '.foo\,bar,.baz', | ||
| 'expected' => array( '.foo\,bar', '.baz' ), | ||
| ), | ||
| 'escaped closing parenthesis in selector function' => array( | ||
| 'selector' => ':is(.a\), .b), .c', | ||
| 'expected' => array( ':is(.a\), .b)', ' .c' ), | ||
| ), | ||
| 'quoted function argument before top-level comma' => array( | ||
| 'selector' => ':lang(zh, "*-hant"),.foo', | ||
| 'expected' => array( ':lang(zh, "*-hant")', '.foo' ), | ||
| ), | ||
| 'escaped quote and comma inside string' => array( | ||
| 'selector' => '[data-x="\",inside"],.b', | ||
| 'expected' => array( '[data-x="\",inside"]', '.b' ), | ||
| ), | ||
| 'comment containing comma' => array( | ||
| 'selector' => '.a/*,*/,.b', | ||
| 'expected' => array( '.a/*,*/', '.b' ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider data_prepend_to_selector_uses_safe_splitting | ||
| * | ||
| * @param string $selector CSS selector list. | ||
| * @param string $expected Expected prepended selector. | ||
| */ | ||
| public function test_prepend_to_selector_uses_safe_splitting( $selector, $expected ) { | ||
| $this->assertSame( | ||
| $expected, | ||
| self::invoke_theme_json_method( 'prepend_to_selector', $selector, '.scope ' ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, array{selector: string, expected: string}> | ||
| */ | ||
| public function data_prepend_to_selector_uses_safe_splitting() { | ||
| return array( | ||
| 'fast path for simple selector list' => array( | ||
| 'selector' => 'h1,h2', | ||
| 'expected' => '.scope h1,.scope h2', | ||
| ), | ||
| 'escaped comma does not trigger fast-path breakage' => array( | ||
| 'selector' => '.foo\,bar,.baz', | ||
| 'expected' => '.scope .foo\,bar,.scope .baz', | ||
| ), | ||
| 'quoted selector function argument is preserved' => array( | ||
| 'selector' => ':lang(zh, "*-hant"),.foo', | ||
| 'expected' => '.scope :lang(zh, "*-hant"),.scope .foo', | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.