ShellStream.Expect(Regex, TimeSpan) properly matches and dequeues data from the _incoming data queue. However, once a match is made, instead of returning all text up to the point of a match, it returns all data within the queue.
Current:
publicstringExpect(Regexregex,TimeSpantimeout){vartext=string.Empty;while(true){lock(_incoming){if(_incoming.Count>0){text=_encoding.GetString(_incoming.ToArray(),0,_incoming.Count);}varmatch=regex.Match(text);if(match.Success){// Remove processed items from the queuefor(vari=0;i<match.Index+match.Length&&_incoming.Count>0;i++){_incoming.Dequeue();}break;}}if(timeout.Ticks>0){if(!_dataReceived.WaitOne(timeout)){returnnull;}}else{_dataReceived.WaitOne();}}returntext;}Fix:
publicstringExpect(Regexregex,TimeSpantimeout){vartext=string.Empty;while(true){lock(_incoming){if(_incoming.Count>0){text=_encoding.GetString(_incoming.ToArray(),0,_incoming.Count);}varmatch=regex.Match(text);if(match.Success){// Remove processed items from the queuefor(vari=0;i<match.Index+match.Length&&_incoming.Count>0;i++){_incoming.Dequeue();}text=text.Substring(0,match.Index+match.Length);// <-- This one line of code fixes it!break;}}if(timeout.Ticks>0){if(!_dataReceived.WaitOne(timeout)){returnnull;}}else{_dataReceived.WaitOne();}}returntext;}
ShellStream.Expect(Regex, TimeSpan) properly matches and dequeues data from the _incoming data queue. However, once a match is made, instead of returning all text up to the point of a match, it returns all data within the queue.
Current:
Fix: