Skip to content

Commit

Permalink
Remove usage of deprecated utf8_encode function
Browse files Browse the repository at this point in the history
utf8_encode is deprecated in PHP 8.2. Fortunately, we're already making
use of iconv, and it's straightforward enough to use iconv to convert
from ISO-8859-1 instead of utf8_encode.
  • Loading branch information
edsrzf committed Feb 22, 2023
1 parent a479ce6 commit 13a775d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Raygun4php/RaygunRequestMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
$utf8_convert_server = function ($value) use (&$utf8_convert_server) {
return is_array($value) ?
array_map($utf8_convert_server, $value) :
iconv('UTF-8', 'UTF-8', utf8_encode($value));
iconv('ISO-8859-1', 'UTF-8', $value);
};

$this->Form = array_map($utf8_convert, $_POST);
Expand Down
15 changes: 15 additions & 0 deletions tests/RaygunClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,19 @@ public function testValidateMessageJsonInTransportObj()
$schemaValidator->validate($data, $this->jsonSchema);
$this->assertTrue($schemaValidator->isValid());
}

/**
* @backupGlobals enabled
*/
public function testServerUtf8Conversion()
{
$_SERVER = [
'a' => 'hello',
'b' => "\xc0\xde",
];
$requestMessage = new RaygunRequestMessage();

$this->assertSame('hello', $requestMessage->Data['a']);
$this->assertSame('ÀÞ', $requestMessage->Data['b']);
}
}

0 comments on commit 13a775d

Please sign in to comment.