Skip to content

Commit

Permalink
fix handling of empty commands
Browse files Browse the repository at this point in the history
  • Loading branch information
EtlamGit committed Jan 7, 2018
1 parent a558022 commit bdfe2af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions source/GrblCommander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ bool GrblCommander::sendRealtime(char command)

void GrblCommander::appendCommand(QString command)
{
// ignore empty lines
if (command.length() == 0)
return;

// append "line feed" if missing
if (command.right(1) != "\n")
if (!command.endsWith("\n"))
command.append('\n');

// append command to command queue
Expand All @@ -110,8 +114,8 @@ void GrblCommander::writeCommands()

// remove comment and spaces at end
command.remove(QRegExp("\\((.*)\\)"));
while (command[command.length()-2] == ' ')
command.remove(command.length()-2,1);
while (command.endsWith(' '))
command.chop(1);

// filter command for forbidden characters
command = command.toUtf8();
Expand Down

0 comments on commit bdfe2af

Please sign in to comment.