-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't trim $filter_name in sanitizeStreamFilter - Fixes filters which…
… pass newline character as an argument.
- Loading branch information
1 parent
1336fd4
commit bfdc19f
Showing
4 changed files
with
60 additions
and
4 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,47 @@ | ||
<?php | ||
|
||
namespace lib; | ||
|
||
use php_user_filter; | ||
|
||
class FilterReplace extends php_user_filter | ||
{ | ||
const FILTER_NAME = 'convert.replace.'; | ||
|
||
private $search; | ||
|
||
private $replace; | ||
|
||
public function onCreate() | ||
{ | ||
if( strpos( $this->filtername, self::FILTER_NAME ) !== 0 ){ | ||
return false; | ||
} | ||
|
||
$params = substr( $this->filtername, strlen( self::FILTER_NAME ) ); | ||
|
||
if( !preg_match( '/([^:]+):([^$]+)$/', $params, $matches ) ){ | ||
return false; | ||
} | ||
|
||
$this->search = $matches[1]; | ||
$this->replace = $matches[2]; | ||
|
||
return true; | ||
} | ||
|
||
public function filter( $in, $out, &$consumed, $closing ) | ||
{ | ||
while( $res = stream_bucket_make_writeable( $in ) ){ | ||
|
||
$res->data = str_replace( $this->search, $this->replace, $res->data ); | ||
|
||
$consumed += $res->datalen; | ||
|
||
/** @noinspection PhpParamsInspection */ | ||
stream_bucket_append( $out, $res ); | ||
} | ||
|
||
return PSFS_PASS_ON; | ||
} | ||
} |
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
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,2 @@ | ||
1,two,3,"new | ||
line" |