From 5427b135d52fc25cebd16bd834d012b2ebcfc49d Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 1 May 2024 16:38:06 +0300 Subject: [PATCH] add message encoding validation --- config/example.json | 4 ++++ src/Server/Ratchet.php | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/config/example.json b/config/example.json index f0220bb..2dd6f28 100644 --- a/config/example.json +++ b/config/example.json @@ -109,6 +109,10 @@ [ "\u001b[31mMessage could not be empty!\u001b[0m" ], + "encoding": + [ + "\u001b[31mInvalid message encoding!\u001b[0m" + ], "internal": [ "\u001b[31mSomething went wrong, please make your feedback!\u001b[0m", diff --git a/src/Server/Ratchet.php b/src/Server/Ratchet.php index 911bc60..26b6f13 100644 --- a/src/Server/Ratchet.php +++ b/src/Server/Ratchet.php @@ -194,6 +194,17 @@ class Ratchet implements MessageComponentInterface ); } + // Check message encoding valid + else if (!mb_check_encoding($connection->message, 'UTF-8')) + { + $connection->send( + implode( + PHP_EOL, + $config->response->submit->failure->encoding + ) . PHP_EOL + ); + } + // Max length already checked on input, begin message save else {