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.
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
[Tag Processor] Merge the test files into a single file #44593
[Tag Processor] Merge the test files into a single file #44593
Changes from 1 commit
0c31584
a279f5d
80452d8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I'm still uncomfortable with re-encoding the tests of
esc_attr()
in our test here. this adds a deep coupling that can come back and frustrate people trying to make unrelated changes.for instance, in our actual code and discussion of the tag processor we have essentially delegated responsibility for attribute encoding and sanitization to
esc_attr()
. we don't do additional work and we don't depend on any particular behavior other than its own guarantees.why should we then extend additional constraints in the tests that we never wanted to make in the code or in conversation? we're not actually testing if this prevents XSS anyway - we're testing that it runs through
esc_attr()
, and I'd rather leave the XSS prevention testing to that function.ultimately this isn't the biggest problem and our code is littered with deeply-coupled integration tests like it, but at the same token our test suite is already in a place where it's frustrating how often tests fail probabilistically and where it can be hard to understand or figure out what's wrong when seemingly-unrelated tests fail.
if we're going to take responsibility for XSS protection and incorporate that code ourselves (which I don't think we'll do) then I think it would be more appropriate to test here. if we're going to delegate to
esc_attr()
then we should either lean on its tests to cover the scenarios, or if it doesn't have them, lean on the history and reporting that has happened over the years to vet it."
->"
, for example, is neither an XSS attack nor evidence that we're protected. it's a good demonstration that we encode the HTML entities and that we won't break out of the syntax;"
->"
does neither and really appears to assert an internal behavior ofesc_attr()
and nothing else.it would be nice if it were easier and natively-available in PHP to create test spies, which is what I was emulating by comparing against
esc_attr( $value )
, but every time I've tried that it involved user-space libraries with particular restrictions.if we want to retain some of these tests then our naming is confusing. we could name it
test_set_attribute_properly_escapes_html_entities()
and then give explanations for the constraints we are setting on it, which would free someone to swap outesc_attr()
while maintaining our requirements. I don't think our requirements are as strict as shown here.I'm not sure if any of the other constraints is really there. the example with
onclick
seems to be covered by the assertion on quotes alone.lots of thoughts 😆
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.
@dmsnell I agree – I only did that to have an automated check in place to confirm that
esc_attr
is indeed used in all the different cases. Ideally we'd have a spy there, but it won't work if we load WordPress. Or maybe it would? We could register theesc_attr
call and augment the return value to something likeESC_ATTR( $original_input )
using a filter.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.
well blimey, we can do this with the
attribute_escape
filterThere 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.
added in 80452d8
should be easy to revert if we need to.
I removed the comment at the top about running this in isolation since we can't anymore; not if we want to assert that we called
esc_attr()
and also verify behaviors ofesc_attr()
. this is fine.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.
Thank you! Looks good to me, too. This PR needs a rebase but should be good otherwise – I'll look into that
This file was deleted.