Skip to content

Commit

Permalink
is_outside_html_attr_context: Utilize helper endswith()
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Mar 2, 2021
1 parent 8de067f commit a532c0c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,26 @@ public function is_html_attr( $content ) {
}

/**
* A helper function which tests whether string ends with some other.
* Tests whether string ends with opening HTML tag for detection in attribute escaping.
*
* @param string $haystack String which is being tested.
* @param string $needle The substring, which we try to locate on the end of the $haystack.
* @param string $function_name Name of function.
* @param string $content Haystack where we look for the end of opening HTML tag.
*
* @return bool True if haystack ends with needle.
* @return bool True if escaping attribute function and string ends with opening HTML tag.
*/
public function endswith( $haystack, $needle ) {
return substr( $haystack, -strlen( $needle ) ) === $needle;
public function is_outside_html_attr_context( $function_name, $content ) {
return $this->escaping_functions[ $function_name ] === 'attr' && $this->endswith( trim( $content ), '>' );
}

/**
* Tests whether string ends with opening HTML tag for detection in attribute escaping.
* A helper function which tests whether string ends with some other.
*
* @param string $function_name Name of function.
* @param string $content Haystack where we look for the end of opening HTML tag.
* @param string $haystack String which is being tested.
* @param string $needle The substring, which we try to locate on the end of the $haystack.
*
* @return bool True if escaping attribute function and string ends with opening HTML tag.
* @return bool True if haystack ends with needle.
*/
public function is_outside_html_attr_context( $function_name, $content ) {
return $this->escaping_functions[ $function_name ] === 'attr' && substr( trim( $content ), -1 ) === '>';
public function endswith( $haystack, $needle ) {
return substr( $haystack, -strlen( $needle ) ) === $needle;
}
}

0 comments on commit a532c0c

Please sign in to comment.