mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
HTML API: Stop counting noop seek operations against the max seek count. #7399
Open
dmsnell
wants to merge
2
commits into
WordPress:trunk
Choose a base branch
from
dmsnell:html-api/stop-counting-void-seeks
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -435,16 +435,49 @@ public function test_limits_the_number_of_bookmarks() { | |
public function test_limits_the_number_of_seek_calls() { | ||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' ); | ||
$processor->next_tag( 'li' ); | ||
$processor->set_bookmark( 'bookmark' ); | ||
|
||
for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) { | ||
$this->assertTrue( $processor->seek( 'bookmark' ), 'Could not seek to the "bookmark"' ); | ||
$processor->set_bookmark( 'ping' ); | ||
$processor->next_tag( 'li' ); | ||
$processor->set_bookmark( 'pong' ); | ||
Comment on lines
+438
to
+440
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. 🏓 |
||
|
||
for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i += 2 ) { | ||
$this->assertTrue( | ||
$processor->seek( 'ping' ), | ||
'Could not seek to the "ping": check test setup.' | ||
); | ||
|
||
$this->assertTrue( | ||
$processor->seek( 'pong' ), | ||
'Could not seek to the "pong": check test setup.' | ||
); | ||
} | ||
|
||
$this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::seek' ); | ||
$this->assertFalse( $processor->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" ); | ||
} | ||
|
||
/** | ||
* @ticket {TICKET_NUMBER} | ||
* | ||
* @covers WP_HTML_Tag_Processor::seek | ||
*/ | ||
public function test_skips_counting_noop_seek_calls() { | ||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' ); | ||
$processor->next_tag( 'li' ); | ||
$processor->set_bookmark( 'here' ); | ||
|
||
for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) { | ||
$this->assertTrue( | ||
$processor->seek( 'here' ), | ||
'Could not seek to the "here": check test setup.' | ||
); | ||
} | ||
|
||
$this->assertTrue( | ||
$processor->seek( 'here' ), | ||
'Should never fail to seek if the seek is pointing at the current location.' | ||
); | ||
} | ||
|
||
/** | ||
* Ensures that it's possible to seek to an earlier location in a document even | ||
* after reaching the end of a document, when most functionality shuts down. | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this impact (or not)
WP_HTML_Processor::seek()
since its actual bookmarks get prefixed with_
?wordpress-develop/src/wp-includes/html-api/class-wp-html-processor.php
Lines 5266 to 5275 in b071c28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't because by the time it calls this parent-class method, it has supplied the underscore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, right. By the way, what is the reasoning behind prefixing bookmarks with underscores in HTML Processor? In WordPress/performance#1546 I'm making use of
WP_HTML_Processor
when available, but in the logic that injects additional markup into thehead
andbody
, it needs to obtain thestart
position of the bookmark. For the HTML Processor version it has to prepend the_
which seems strange, although granted this is an internal API:WP_HTML_Tag_Processor
versionWP_HTML_Processor
versionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason was to avoid any possible conflicts between bookmarks set by the HTML Processor itself, and the user-space code setting bookmarks. that is, any time someone calls
WP_HTML_Processor::set_bookmark()
it will be prefixed, but calls inside the processor toparent::set_bookmark()
will be un-prefixed. it's a very basic namespacing mechanism.