Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProperEscapingFunction: further improve attribute matching #681

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ProperEscapingFunction: further improve attribute matching
Prior to VIPCS 2.3.0, equal signs not followed by quotes were ignored by this sniff, even though unquoted values for attributes in HTML is supported as long as the value does not contain whitespace.

However, detecting equal signs not followed by quotes could confuse the attribute detecting as equal signs without quotes can also be used outside of HTML attribute context.

This improves the attribute detection further by making sure that an equal sign (with or without subsequent quotes) is preceded by at least one alphanumeric character to indicate it _could_ be an HTML attribute.

Includes tests.

Fixes 680
jrfnl committed Apr 24, 2021
commit a2ab68842adf469af97f72ea6b57fc44b621e3fb
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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/>