Skip to content

Commit

Permalink
fix: Crashpad received a malformed value as an update (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahradelahi authored Jun 24, 2024
1 parent 5411909 commit c2c621c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/CrashPad.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function enableCrashHandler(): void
{
$handler = function (Throwable $throwable) {
if (Telegram::getAdminId() !== -1) {
$input = getenv('TG_CURRENT_UPDATE') ?? Telegram::getInput();
$input = Telegram::getInput();
CrashPad::sendCrash(Telegram::getAdminId(), $throwable, $input);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Entities/InlineKeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class InlineKeyboardButton extends KeyboardButton
/**
* Creates instance of InlineKeyboardButton
*
* @param string $string
* @param string|null $label
* @return InlineKeyboardButton
*/
public static function make(string $string): InlineKeyboardButton
public static function make(string|null $label = null): InlineKeyboardButton
{
return new self($string);
return new self($label);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Entities/KeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public function __construct($data)
$data = ['text' => $data];
}

parent::__construct($data);
parent::__construct($data ?? []);
}

/**
* Creates instance of KeyboardButton
*
* @param string $string
* @param string|null $label
* @return KeyboardButton
*/
public static function make(string $string): KeyboardButton
public static function make(string|null $label = null): KeyboardButton
{
return new self($string);
return new self($label);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ public static function getUpdate(): Update|null
*/
public static function getInput(): string|null
{
return file_get_contents('php://input') ?? null;
$input = file_get_contents('php://input');
if (!empty($input)) {
return $input;
}

$env = getenv('TG_CURRENT_UPDATE');
if (!empty($env) && is_string($env)) {
return $env;
}

return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/KeyboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ public function test_create_for_answer_query(): void
$this->assertEquals(json_encode($raw_data), $result['options']['query']['reply_markup']);
}

}
}

0 comments on commit c2c621c

Please sign in to comment.