Skip to content

Commit

Permalink
ProperEscapingFunction: deprecate, don't remove
Browse files Browse the repository at this point in the history
... the `public` methods and as those use the `private` properties and extending sniffs may rely on the functionality of the `public` methods, we can't removed the `private` properties yet either, so deprecating those too.
  • Loading branch information
jrfnl committed Apr 22, 2021
1 parent 1401543 commit a615109
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ class ProperEscapingFunctionSniff extends Sniff {
T_NS_SEPARATOR => T_NS_SEPARATOR,
];

/**
* List of attributes associated with url outputs.
*
* @deprecated 2.3.1 Currently unused by the sniff, but needed for
* for public methods which extending sniffs may be
* relying on.
*
* @var array
*/
private $url_attrs = [
'href',
'src',
'url',
'action',
];

/**
* List of syntaxes for inside attribute detection.
*
* @deprecated 2.3.1 Currently unused by the sniff, but needed for
* for public methods which extending sniffs may be
* relying on.
*
* @var array
*/
private $attr_endings = [
'=',
'="',
"='",
"=\\'",
'=\\"',
];

/**
* Returns an array of tokens this test wants to listen for.
*
Expand Down Expand Up @@ -133,6 +166,48 @@ public function process_token( $stackPtr ) {
}
}

/**
* Tests whether provided string ends with open attribute which expects a URL value.
*
* @deprecated 2.3.1
*
* @param string $content Haystack in which we look for an open attribute which exects a URL value.
*
* @return bool True if string ends with open attribute which expects a URL value.
*/
public function attr_expects_url( $content ) {
$attr_expects_url = false;
foreach ( $this->url_attrs as $attr ) {
foreach ( $this->attr_endings as $ending ) {
if ( $this->endswith( $content, $attr . $ending ) === true ) {
$attr_expects_url = true;
break;
}
}
}
return $attr_expects_url;
}

/**
* Tests whether provided string ends with open HMTL attribute.
*
* @deprecated 2.3.1
*
* @param string $content Haystack in which we look for open HTML attribute.
*
* @return bool True if string ends with open HTML attribute.
*/
public function is_html_attr( $content ) {
$is_html_attr = false;
foreach ( $this->attr_endings as $ending ) {
if ( $this->endswith( $content, $ending ) === true ) {
$is_html_attr = true;
break;
}
}
return $is_html_attr;
}

/**
* Tests whether an attribute escaping function is being used outside of an HTML tag.
*
Expand Down

0 comments on commit a615109

Please sign in to comment.