-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
188 additions
and
56 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
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,27 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Contracts\Sanitizer; | ||
|
||
class FilterVars implements Sanitizer | ||
{ | ||
private $filter; | ||
private $options; | ||
|
||
public function __construct(int $filter = FILTER_DEFAULT, $options = null) | ||
{ | ||
$this->filter = $filter; | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* @param $input | ||
* @return string | ||
*/ | ||
public function sanitize($input) | ||
{ | ||
return filter_var($input, $this->filter, $this->options); | ||
} | ||
|
||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\Capitalize; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class CapitalizeTest extends TestCase | ||
{ | ||
public function test_capitalize_sanitizer() | ||
{ | ||
$sanitizer = new Capitalize(); | ||
$output = $sanitizer->sanitize('test'); | ||
$this->assertEquals('Test', $output); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\FilterVars; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class FilterVarsTest extends TestCase | ||
{ | ||
public function test_strip_tags_with_filter_vars() | ||
{ | ||
$filter = FILTER_SANITIZE_STRING; | ||
$sanitizer = new FilterVars($filter); | ||
$output = $sanitizer->sanitize("<script>malicious code</script>"); | ||
$this->assertEquals('malicious code', $output); | ||
} | ||
|
||
public function test_apply_default_filter_when_no_params_have_been_provided_in_filter_vars() | ||
{ | ||
$sanitizer = new FilterVars(); | ||
$output = $sanitizer->sanitize("no filter applied"); | ||
$this->assertEquals('no filter applied', $output); | ||
} | ||
|
||
public function test_pass_filter_options_to_filter_vars() | ||
{ | ||
$filter = FILTER_SANITIZE_NUMBER_FLOAT; | ||
$options = FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND; | ||
$sanitizer = new FilterVars($filter, $options); | ||
$output = $sanitizer->sanitize("442.34,34notallowed"); | ||
$this->assertEquals("442.34,34", $output); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\Lowercase; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class LowercaseTest extends TestCase | ||
{ | ||
public function test_lowercase_sanitizer() | ||
{ | ||
$sanitizer = new Lowercase(); | ||
$output = $sanitizer->sanitize('TEST'); | ||
$this->assertEquals('test', $output); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\RemoveNonNumeric; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class RemoveNonNumericTest extends TestCase | ||
{ | ||
public function test_remove_non_numeric_sanitizer() | ||
{ | ||
$sanitizer = new RemoveNonNumeric(); | ||
$output = $sanitizer->sanitize('test1234-134AC~'); | ||
$this->assertEquals('1234134', $output); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\TrimDuplicateSpaces; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class TrimDuplicateSpacesTest extends TestCase | ||
{ | ||
public function test_trim_duplicate_spaces_sanitizer() | ||
{ | ||
$sanitizer = new TrimDuplicateSpaces(); | ||
$output = $sanitizer->sanitize('test '); | ||
$this->assertEquals('test ', $output); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\Trim; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class TrimTest extends TestCase | ||
{ | ||
public function test_trim_sanitizer() | ||
{ | ||
$sanitizer = new Trim(); | ||
$output = $sanitizer->sanitize('test '); | ||
$this->assertEquals('test', $output); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ArondeParon\RequestSanitizer\Tests\Sanitizers; | ||
|
||
use ArondeParon\RequestSanitizer\Sanitizers\Uppercase; | ||
use ArondeParon\RequestSanitizer\Tests\TestCase; | ||
|
||
class UppercaseTest extends TestCase | ||
{ | ||
public function test_uppercase_sanitizer() | ||
{ | ||
$sanitizer = new Uppercase(); | ||
$output = $sanitizer->sanitize('test'); | ||
$this->assertEquals('TEST', $output); | ||
} | ||
} |