Skip to content

Commit

Permalink
Fixed bug #1462 : Error processing cyrillic strings in Tokenizer
Browse files Browse the repository at this point in the history
The error from iconv_strlen when a string contains invalid chars (based on the encoding) was no longer being muted due to the new error handler in the Runner class. This commit replaces the mute operator with an error_reporting change to properly mute that error again and allow files to be checked even with mixed encoding.
  • Loading branch information
gsherwood committed Nov 15, 2017
1 parent 1dc8729 commit 235b59c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Default remains at 1
-- Thanks to Nikola Kovacs for the patch
- PEAR.Functions.FunctionCallSignature now requires the function keyword to be indented to an exact tab stop
- Fixed bug #1462 : Error processing cyrillic strings in Tokenizer
- Fixed bug #1590 : InlineControlStructure CBF issue while adding braces to an if thats returning a nested function
- Fixed bug #1718 : Unclosed strings at EOF sometimes tokenized as T_WHITESPACE by the JS tokenizer
- Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs
Expand Down
5 changes: 5 additions & 0 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@ private function run()
*/
public function handleErrors($code, $message, $file, $line)
{
if ((error_reporting() & $code) === 0) {
// This type of error is being muted.
return true;
}

throw new RuntimeException("$message in $file on line $line");

}//end handleErrors()
Expand Down
11 changes: 9 additions & 2 deletions src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ private function createPositionMap()
// There are no tabs in this content, or we aren't replacing them.
if ($checkEncoding === true) {
// Not using the default encoding, so take a bit more care.
$length = @iconv_strlen($this->tokens[$i]['content'], $this->config->encoding);
$oldLevel = error_reporting();
error_reporting(0);
$length = iconv_strlen($this->tokens[$i]['content'], $this->config->encoding);
error_reporting($oldLevel);

if ($length === false) {
// String contained invalid characters, so revert to default.
$length = strlen($this->tokens[$i]['content']);
Expand Down Expand Up @@ -466,7 +470,10 @@ public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ')
$newContent .= $content;
if ($checkEncoding === true) {
// Not using the default encoding, so take a bit more care.
$contentLength = @iconv_strlen($content, $this->config->encoding);
$oldLevel = error_reporting();
error_reporting(0);
$contentLength = iconv_strlen($content, $this->config->encoding);
error_reporting($oldLevel);
if ($contentLength === false) {
// String contained invalid characters, so revert to default.
$contentLength = strlen($content);
Expand Down

0 comments on commit 235b59c

Please sign in to comment.