Skip to content

Commit

Permalink
Prevent C0 control codes (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher authored Aug 4, 2023
1 parent bb48119 commit aecf6f3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
14 changes: 1 addition & 13 deletions src/Concerns/TypedValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ trait TypedValue
*/
protected int $cursorPosition = 0;

/**
* Keys to ignore
*
* @var array<string>
*/
protected array $ignore = [
Key::ENTER,
Key::TAB,
Key::CTRL_C,
Key::CTRL_D,
];

/**
* Track the value as the user types.
*/
Expand Down Expand Up @@ -64,7 +52,7 @@ protected function trackTypedValue(string $default = '', bool $submit = true): v

$this->typedValue = mb_substr($this->typedValue, 0, $this->cursorPosition - 1).mb_substr($this->typedValue, $this->cursorPosition);
$this->cursorPosition--;
} elseif (! in_array($key, $this->ignore)) {
} elseif (ord($key) >= 32) {
$this->typedValue = mb_substr($this->typedValue, 0, $this->cursorPosition).$key.mb_substr($this->typedValue, $this->cursorPosition);
$this->cursorPosition++;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ class Key
const SHIFT_TAB = "\e[Z";

const CTRL_C = "\x03";

const CTRL_D = "\x04";
}

0 comments on commit aecf6f3

Please sign in to comment.