Skip to content

Commit

Permalink
ProperEscapingFunction: fine-tune attribute regex
Browse files Browse the repository at this point in the history
This adds test cases with:
* No space before "action" as it is at the start of the line in a multi-line text string.
* A tab before "action".

... and makes minor adjustments to the regex to safeguard handling these cases correctly.
  • Loading branch information
jrfnl committed Apr 22, 2021
1 parent 7f77f90 commit 1401543
Show file tree
Hide file tree
Showing 3 changed files with 13 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)?=(?:\\\\)?["\']*$`i';

/**
* List of escaping functions which are being tested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@ echo 'data-param-url="' . Esc_HTML::static_method( $share_url ) . '"'; // OK.

// Not a target for this sniff (yet).
printf( '<meta name="generator" content="%s">', esc_attr( $content ) ); // OK.
?>

// Making sure tabs and new lines before "action" are handled correctly.
<input class="something something-else something-more"
action="<?php echo esc_attr( $my_var ); ?>"><!-- Error. -->
<?php
echo '<input class="something something-else something-more"
action="', esc_url( $my_var ), '">'; // OK.
echo '<input class="something something-else something-more"
action="', esc_attr( $my_var ), '">'; // Error.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function getErrorList() {
79 => 1,
80 => 1,
82 => 1,
92 => 1,
97 => 1,
];
}

Expand Down

0 comments on commit 1401543

Please sign in to comment.