1818 */
1919class ProperEscapingFunctionSniff extends Sniff {
2020
21+ /**
22+ * Regular expression to match the end of HTML attributes.
23+ *
24+ * @var string
25+ */
26+ const ATTR_END_REGEX = '`(?<attrname>href|src|url|(^|\s+)action)?=(?: \\\\)?[" \']*$`i ' ;
27+
2128 /**
2229 * List of escaping functions which are being tested.
2330 *
@@ -52,6 +59,10 @@ class ProperEscapingFunctionSniff extends Sniff {
5259 /**
5360 * List of attributes associated with url outputs.
5461 *
62+ * @deprecated 2.3.1 Currently unused by the sniff, but needed for
63+ * for public methods which extending sniffs may be
64+ * relying on.
65+ *
5566 * @var array
5667 */
5768 private $ url_attrs = [
@@ -64,6 +75,10 @@ class ProperEscapingFunctionSniff extends Sniff {
6475 /**
6576 * List of syntaxes for inside attribute detection.
6677 *
78+ * @deprecated 2.3.1 Currently unused by the sniff, but needed for
79+ * for public methods which extending sniffs may be
80+ * relying on.
81+ *
6782 * @var array
6883 */
6984 private $ attr_endings = [
@@ -134,13 +149,17 @@ public function process_token( $stackPtr ) {
134149 return ;
135150 }
136151
137- if ( $ escaping_type !== 'url ' && $ this ->attr_expects_url ( $ content ) ) {
152+ if ( preg_match ( self ::ATTR_END_REGEX , $ content , $ matches ) !== 1 ) {
153+ return ;
154+ }
155+
156+ if ( $ escaping_type !== 'url ' && empty ( $ matches ['attrname ' ] ) === false ) {
138157 $ message = 'Wrong escaping function. href, src, and action attributes should be escaped by `esc_url()`, not by `%s()`. ' ;
139158 $ this ->phpcsFile ->addError ( $ message , $ stackPtr , 'hrefSrcEscUrl ' , $ data );
140159 return ;
141160 }
142161
143- if ( $ escaping_type === 'html ' && $ this -> is_html_attr ( $ content ) ) {
162+ if ( $ escaping_type === 'html ' ) {
144163 $ message = 'Wrong escaping function. HTML attributes should be escaped by `esc_attr()`, not by `%s()`. ' ;
145164 $ this ->phpcsFile ->addError ( $ message , $ stackPtr , 'htmlAttrNotByEscHTML ' , $ data );
146165 return ;
@@ -150,6 +169,8 @@ public function process_token( $stackPtr ) {
150169 /**
151170 * Tests whether provided string ends with open attribute which expects a URL value.
152171 *
172+ * @deprecated 2.3.1
173+ *
153174 * @param string $content Haystack in which we look for an open attribute which exects a URL value.
154175 *
155176 * @return bool True if string ends with open attribute which expects a URL value.
@@ -170,6 +191,8 @@ public function attr_expects_url( $content ) {
170191 /**
171192 * Tests whether provided string ends with open HMTL attribute.
172193 *
194+ * @deprecated 2.3.1
195+ *
173196 * @param string $content Haystack in which we look for open HTML attribute.
174197 *
175198 * @return bool True if string ends with open HTML attribute.
0 commit comments