mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-23 16:14:23 +00:00
Shell: Add POSIX-compliant character escaping
POSIX.1-2017, Shells & Utilities, section 2.2
This commit is contained in:
committed by
Andreas Kling
parent
2d24b12a34
commit
f44e7dc5d0
@@ -84,6 +84,16 @@ Vector<Command> Parser::parse()
|
||||
m_state = State::InRedirectionPath;
|
||||
break;
|
||||
}
|
||||
if (ch == '\\') {
|
||||
if (i == m_input.length() - 1) {
|
||||
fprintf(stderr, "Syntax error: Nothing to escape (\\)\n");
|
||||
return {};
|
||||
}
|
||||
char next_ch = m_input.characters()[i + 1];
|
||||
m_token.append(next_ch);
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
if (ch == '\'') {
|
||||
m_state = State::InSingleQuotes;
|
||||
break;
|
||||
@@ -147,6 +157,21 @@ Vector<Command> Parser::parse()
|
||||
m_state = State::Free;
|
||||
break;
|
||||
}
|
||||
if (ch == '\\') {
|
||||
if (i == m_input.length() - 1) {
|
||||
fprintf(stderr, "Syntax error: Nothing to escape (\\)\n");
|
||||
return {};
|
||||
}
|
||||
char next_ch = m_input.characters()[i + 1];
|
||||
if (next_ch == '$' || next_ch == '`'
|
||||
|| next_ch == '"' || next_ch == '\\') {
|
||||
m_token.append(next_ch);
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
m_token.append('\\');
|
||||
break;
|
||||
}
|
||||
m_token.append(ch);
|
||||
break;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user