This repository has been archived by the owner on Jul 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for EscapingCheck, and update the latter a bit
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
require_once( 'CodeCheckTestBase.php' ); | ||
|
||
class EscapingTest extends CodeCheckTestBase { | ||
|
||
public function testEscaping() { | ||
$expected_errors = array( | ||
array( 'slug' => 'functions-file', | ||
'level' => BaseScanner::LEVEL_BLOCKER, | ||
'description' => sprintf( | ||
__( 'The function %1$s is being passed as the first parameter of %2$s. This is problematic because %1$s echoes a string which will not be escaped by %2$s.', 'vip-scanner' ), | ||
'<code>printf()</code>', | ||
'<code>esc_attr()</code>' | ||
), | ||
'file' => 'EscapingTest.inc', | ||
'lines' => 5, | ||
), | ||
array( 'slug' => 'functions-file', | ||
'level' => BaseScanner::LEVEL_BLOCKER, | ||
'description' => sprintf( | ||
__( '%1$s is being passed as the first parameter of %2$s.', 'vip-scanner' ), | ||
'<code>print</code>', | ||
'<code>esc_attr()</code>' | ||
), | ||
'file' => 'EscapingTest.inc', | ||
'lines' => 6, | ||
), | ||
array( 'slug' => 'functions-file', | ||
'level' => BaseScanner::LEVEL_BLOCKER, | ||
'description' => sprintf( | ||
__( '%1$s is being passed as the first parameter of %2$s.', 'vip-scanner' ), | ||
'<code>echo</code>', | ||
'<code>esc_attr()</code>' | ||
), | ||
'file' => 'EscapingTest.inc', | ||
'lines' => 7, | ||
), | ||
array( 'slug' => 'functions-file', | ||
'level' => BaseScanner::LEVEL_BLOCKER, | ||
'description' => sprintf( | ||
__( 'Please use %1$s to echo internationalized text in html attributes.', 'vip-scanner' ), | ||
'<code>esc_attr_e()</code>' | ||
), | ||
'file' => 'EscapingTest.inc', | ||
'lines' => 10, | ||
), | ||
array( 'slug' => 'functions-file', | ||
'level' => BaseScanner::LEVEL_BLOCKER, | ||
'description' => sprintf( | ||
__( 'Please use %1$s to echo internationalized text in html attributes.', 'vip-scanner' ), | ||
'<code>esc_attr_e()</code>' | ||
), | ||
'file' => 'EscapingTest.inc', | ||
'lines' => 11, | ||
), | ||
); | ||
$actual_errors = $this->checkFile( 'EscapingTest.inc' ); | ||
$this->assertEqualErrors( $expected_errors, $actual_errors ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
die(); //Don't actually run the following code. | ||
|
||
esc_attr( printf( 'unescaped string' ) ); | ||
esc_attr( print 'unescaped string' ); | ||
esc_attr( echo 'unescaped string' ); | ||
?> | ||
|
||
<a title="<?php _e( 'unescaped HTML attribute' ); ?>" /> | ||
<a title='<?php _e( 'unescaped HTML attribute' ); ?>' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters