Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add console string quoting. #705

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RobertPHeller
Copy link
Contributor

This is a new attempt to get this into the root fork. I need this patch for my command station code. This is a feature enhancement to allow consoles to allow quoting command line parameters, specificly to allow command line parameters with spaces and other word break characters.

@RobertPHeller
Copy link
Contributor Author

Is there some reason this pull request has not been acted on? Is the ArduinoBuild / Build ESP32 examples build failure check holding it up?

@atanisoft
Copy link
Collaborator

Is the ArduinoBuild / Build ESP32 examples build failure check holding it up?

that can be ignored as it is trying to use the latest arduino-esp32 that isn't supported on master (and won't be anytime soon).

@RobertPHeller
Copy link
Contributor Author

So, what is holding up the pull request? I would like to be synced and up-to-date, but I need this update for my PocketBeagle command station, so the version of OpenMRN on my BeagleBone build box is being held back waiting for this PR...

@RobertPHeller
Copy link
Contributor Author

Is there something I need to do to get this pull request approved?

case '"':
/** @todo quoted arguments not yet supported */
/// Quote handling added (Robert Heller <[email protected]>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, the git history keeps track of who added what code and why.
If you are looking to permanently record your name for the licensing, add it to line 30.

else if (quote == '\0')
{ /* Start of quoted */
quote = line[i]; // Save the quote mark
if ((i + 1) < pos)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of this if, which duplicates code from elsewhere, it would be enough to have these two statements:

   last = quote;
   line[i] = '\0';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand. Might it be you mean:
last = '\0';
?

And what about a check for a loose quote at EOL?

@@ -22,7 +22,7 @@ TEST(ConsoleTest, testHelp)
" has an effect on socket based logins sessions\n"
"> ", 154));

EXPECT_EQ(::write(s, "?\n", 3), 3);
EXPECT_EQ(::write(s, "?\n", 5), 5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not seem right. There are only three characters in that string (question mark, newline, zero). We should not write 5 bytes here.

if (argc == 0) {
fprintf(fp, "the echo command\n");
} else if (argc == 2) {
fprintf(fp, "%s\n", argv[2]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argv[1]
(because argv[argc] should always be NULL)

EXPECT_EQ(::write(s, "echo '\"Oh no, no, no\", said the man'\n", 37), 37);
usleep(1000);
EXPECT_EQ(::read(s, buf, 1024), 32);
EXPECT_TRUE(!strncmp(buf, "\"Oh no, no, no\", said the man\n> ", 32));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding another test case with mismatched quote to exercise the error path as well. This will be helpful to keep test coverage high.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants