telnet-client icon indicating copy to clipboard operation
telnet-client copied to clipboard

Error prompt not detected if prompt is set to empty string

Open biggianteye opened this issue 5 years ago • 1 comments

If $prompt is set to an empty string ("") and $promptError is set as non-empty (eg. "ERROR") then any error condition is never detected.

Using the example from the README, this is what would happen:

Graze\TelnetClient\TelnetResponse {#188
  #isError: false
  #responseText: "I'm sorry, Dave. I'm afraid I can't do that\nERROR"
  #promptMatches: array:1 [
    0 => ""
  ]
}

The reason that this happens is that prompt checking (getResponse() in Graze\TelnetClient\TelnetClient) happens before error checking. In the case of an empty prompt it always matches and so the error prompt check never happens.

Some thoughts on fixes:

  • Change the ordering such that error prompt checking happens first.
  • Don't attempt any matching if a prompt is an empty string

biggianteye avatar Sep 13 '19 10:09 biggianteye

(Note that I didn't actually test out what the exact response of that command would be. It's an educated guess based on my reading of the code.)

biggianteye avatar Sep 13 '19 11:09 biggianteye