From fb361bfaa4266fd860505350cd0267e84830746d Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 6 Jul 2018 15:08:18 +0000 Subject: [PATCH] console : manage correctely the bad provided values git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4264 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- console.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/console.php b/console.php index 95a289e..b69ebbe 100644 --- a/console.php +++ b/console.php @@ -292,7 +292,7 @@ class console $completeArr = call_user_func ($this->completionFunction, $string); $isAssoc = is_array ($completeArr) && array_diff_key ($completeArr, array_keys (array_keys ($completeArr))); - if (count ($completeArr) === 1) + if (is_array ($completeArr) && count ($completeArr) === 1) { if (substr ($string, -1) !== " ") { @@ -314,7 +314,7 @@ class console else $string .= reset ($completeArr); } - else + elseif (is_array ($completeArr) && count ($completeArr)) { // Multiple answers : display them // Manage if all the answers start by the same chars : add them to the @@ -358,9 +358,12 @@ class console echo "\n".implode ("\n", $completeArr)."\n"; } } - $cursorPos = mb_strlen ($prompt.$string) + 1; - $this->rewriteLine ($prompt.$string); - $this->moveCursor ($cursorPos); + if (is_array ($completeArr) && count ($completeArr)) + { + $cursorPos = mb_strlen ($prompt.$string) + 1; + $this->rewriteLine ($prompt.$string); + $this->moveCursor ($cursorPos); + } } // }}} elseif (ord ($char) === 3) @@ -377,7 +380,7 @@ class console // Logout (Ctrl+D) // {{{ { - $string = "exit"; + $string = "exit\n"; $this->rewriteLine ($prompt.$string); return $string; } @@ -841,6 +844,8 @@ class console private function shortestIdenticalValues ($completeArr) // {{{ { + if (! is_array ($completeArr)) + return ""; $minlen = 99999; foreach ($completeArr as $val) {