mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Shell: Add POSIX-compliant character escaping
POSIX.1-2017, Shells & Utilities, section 2.2
This commit is contained in:
parent
2d24b12a34
commit
f44e7dc5d0
Notes:
sideshowbarker
2024-07-19 12:06:53 +09:00
Author: https://github.com/malpas Commit: https://github.com/SerenityOS/serenity/commit/f44e7dc5d09 Pull-request: https://github.com/SerenityOS/serenity/pull/562
1 changed files with 25 additions and 0 deletions
|
@ -84,6 +84,16 @@ Vector<Command> Parser::parse()
|
||||||
m_state = State::InRedirectionPath;
|
m_state = State::InRedirectionPath;
|
||||||
break;
|
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 == '\'') {
|
if (ch == '\'') {
|
||||||
m_state = State::InSingleQuotes;
|
m_state = State::InSingleQuotes;
|
||||||
break;
|
break;
|
||||||
|
@ -147,6 +157,21 @@ Vector<Command> Parser::parse()
|
||||||
m_state = State::Free;
|
m_state = State::Free;
|
||||||
break;
|
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);
|
m_token.append(ch);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue