Skip to content
Snippets Groups Projects
Commit 4713fc01 authored by Hunter Goldstein's avatar Hunter Goldstein Committed by Michael Aaron Murphy
Browse files

Resolve quotes not being an escaped character (#399)

* Add double and single quotes to escaped chars

* Fix outstanding bugs for pipeline and escaped chars
parent 9f5bc2aa
No related branches found
No related tags found
No related merge requests found
......@@ -126,6 +126,12 @@ impl<'a> Collector<'a> {
bytes.next();
self.single_quoted(bytes, i)?;
},
// If we see a backslash, assume that it is leading up to an escaped character
// and skip the next character
b'\\' => {
bytes.next();
bytes.next();
}
// If we see a byte from the follow set, we've definitely reached the end of
// the arguments
c if FOLLOW_ARGS.contains(&c) && is_toplevel!() => {
......@@ -136,6 +142,18 @@ impl<'a> Collector<'a> {
_ => { bytes.next(); }
}
}
if proc_level > 0 {
return Err("ion: syntax error: unmatched left paren");
}
if array_level > 0 {
return Err("ion: syntax error: unmatched left bracket");
}
if proc_level < 0 {
return Err("ion: syntax error: extra right paren(s)");
}
if array_level < 0 {
return Err("ion: syntax error: extra right bracket(s)");
}
match (start, end) {
(Some(i), Some(j)) if i < j => Ok(Some(&self.data[i..j])),
(Some(i), None) => Ok(Some(&self.data[i..])),
......@@ -730,4 +748,23 @@ mod tests {
assert!(false);
}
}
#[test]
fn escaped_filenames() {
let input = "echo zardoz >> foo\\'bar";
let expected = Pipeline {
jobs: vec![
Job::new(Array::from_vec(vec!["echo".into(), "zardoz".into()]), JobKind::Last),
],
stdin: None,
stdout: Some(Redirection {
from: RedirectFrom::Stdout,
file: "foo\\'bar".into(),
append: true
})
};
assert_eq!(parse(input), Statement::Pipeline(expected));
}
}
......@@ -99,7 +99,8 @@ fn escape(input: &str) -> String {
for character in input.bytes() {
match character {
b'(' | b')' | b'[' | b']' | b'&' | b'$' |
b'@' | b'{' | b'}' | b'<' | b'>' | b';' => output.push(b'\\'),
b'@' | b'{' | b'}' | b'<' | b'>' | b';' |
b'"' | b'\'' => output.push(b'\\'),
_ => ()
}
output.push(character);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment