Skip to content

Commit

Permalink
Merge pull request #681 from Automattic/fix/680-properescapingfunctio…
Browse files Browse the repository at this point in the history
…ns-match-precision

ProperEscapingFunction: further improve attribute matching
  • Loading branch information
rebeccahum authored Apr 26, 2021
2 parents 7666bf2 + a2ab688 commit b40582c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProperEscapingFunctionSniff extends Sniff {
*
* @var string
*/
const ATTR_END_REGEX = '`(?<attrname>href|src|url|(^|\s+)action)?=(?:\\\\)?["\']*$`i';
const ATTR_END_REGEX = '`(?<attrname>href|src|url|(^|\s+)action)?(?<=[a-z0-9_-])=(?:\\\\)?["\']*$`i';

/**
* List of escaping functions which are being tested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ echo '<a href="', esc_html($url), '">'; // Error.
<div>html</div>
<?= '<h1 class="', esc_attr( $test ), '">'; ?><!-- OK -->
<div>html</div>

// Issue #680 - only match = when preceeded by something which could be an HTML attribute.
<option value="<?php echo esc_attr( $i ); ?>" <?php echo ( $filter_importance === $i ) ? 'selected' : ''; ?> >
&gt;=<?php echo esc_html( $i ); ?>
</option>

<A HREF="<?= esc_url($url) ?>" data-num2=<?= esc_attr( $num2 )><?php echo esc_html( $link ); ?><a/>

0 comments on commit b40582c

Please sign in to comment.