Skip to content

Commit

Permalink
[9.x] Fix Queue failed logging exception UNICODE (#41020)
Browse files Browse the repository at this point in the history
Issues :
#24263
#41016
  • Loading branch information
boomhq committed Feb 16, 2022
1 parent c5166e8 commit 6e44b09
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function log($connection, $queue, $payload, $exception)
{
$failed_at = Date::now();

$exception = (string) $exception;
$exception = (string) mb_convert_encoding($exception, 'UTF-8');

return $this->getTable()->insertGetId(compact(
'connection', 'queue', 'payload', 'exception', 'failed_at'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function log($connection, $queue, $payload, $exception)
'connection' => $connection,
'queue' => $queue,
'payload' => $payload,
'exception' => (string) $exception,
'exception' => (string) mb_convert_encoding($exception, 'UTF-8'),
'failed_at' => Date::now(),
]);

Expand Down
32 changes: 32 additions & 0 deletions tests/Queue/DatabaseFailedJobProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Illuminate\Tests\Queue;

use Exception;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Str;
use PHPUnit\Framework\TestCase;

class DatabaseFailedJobProviderTest extends TestCase
Expand Down Expand Up @@ -39,4 +41,34 @@ public function testCanFlushFailedJobs()
$provider->flush(10 * 24);
$this->assertSame(0, $db->getConnection()->table('failed_jobs')->count());
}

public function testCanProperlyLogFailedJob()
{
$db = new DB;
$db->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
]);

$db->getConnection()->getSchemaBuilder()->create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});

$uuid = Str::uuid();

$exception = new Exception(utf8_decode('ÐÑÙ0E\xE2\x�98\xA0World��7B¹!þÿ'));
$provider = new DatabaseFailedJobProvider($db->getDatabaseManager(), 'default', 'failed_jobs');

$provider->log('database', 'default', json_encode(['uuid' => (string) $uuid]), $exception);

$exception = (string) mb_convert_encoding($exception, 'UTF-8');

$this->assertSame(1, $db->getConnection()->table('failed_jobs')->count());
$this->assertSame($exception, $db->getConnection()->table('failed_jobs')->first()->exception);
}
}

0 comments on commit 6e44b09

Please sign in to comment.