mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
Shell: Allow empty tokens if enclosed in single or double quotes
Previously the shell parser would discard empty tokens. We now allow them when they are enclosed in quotes (either '' or "") This means that a command like _echo ""_ will actually pass an empty string to /bin/echo in argv[1] now.
This commit is contained in:
parent
003d52ce6e
commit
ed90d39cd7
2 changed files with 6 additions and 5 deletions
|
@ -29,9 +29,9 @@
|
|||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void Parser::commit_token()
|
||||
void Parser::commit_token(AllowEmptyToken allow_empty)
|
||||
{
|
||||
if (m_token.is_empty())
|
||||
if (allow_empty == AllowEmptyToken::No && m_token.is_empty())
|
||||
return;
|
||||
if (m_state == InRedirectionPath) {
|
||||
m_redirections.last().path = String::copy(m_token);
|
||||
|
@ -239,7 +239,7 @@ Vector<Command> Parser::parse()
|
|||
break;
|
||||
case State::InSingleQuotes:
|
||||
if (ch == '\'') {
|
||||
commit_token();
|
||||
commit_token(AllowEmptyToken::Yes);
|
||||
m_state = State::Free;
|
||||
break;
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ Vector<Command> Parser::parse()
|
|||
break;
|
||||
case State::InDoubleQuotes:
|
||||
if (ch == '\"') {
|
||||
commit_token();
|
||||
commit_token(AllowEmptyToken::Yes);
|
||||
m_state = State::Free;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue