diff --git a/examples/methods.ion b/examples/methods.ion index 768dfa97fcbe73484f0130cbae34d0fe93cad1c8..00f9df4d3744fb1263b9ab8d88ccd14c4dc6b300 100644 --- a/examples/methods.ion +++ b/examples/methods.ion @@ -35,4 +35,8 @@ echo $replace($join([one two three], "\n"), "\n" "\t") let a = "applesauce" let pos = $find(a, "s") let array = [@split_at(a, $pos)] -echo $join(array, "\n") \ No newline at end of file +echo $join(array, "\n") + +let a = [1 2 3 4 5] +let a = "1 2 3 4 5" +echo $join(@split(a, " "), $join(a, " ")) diff --git a/examples/methods.out b/examples/methods.out index b64222956262039121094a0eed07bfe3988e893d..dfb76765f445719d9b3da9a6149aebf4fc388068 100644 --- a/examples/methods.out +++ b/examples/methods.out @@ -65,3 +65,4 @@ one\ntwo\nthree one two three apple sauce +11 2 3 4 521 2 3 4 531 2 3 4 541 2 3 4 55 diff --git a/src/parser/shell_expand/words/methods/strings.rs b/src/parser/shell_expand/words/methods/strings.rs index 7135d44ccb128bc9f76f50b779c136e2244f51e9..dfb8abb0403d907b83f063bfdfd9af00b4c8918c 100644 --- a/src/parser/shell_expand/words/methods/strings.rs +++ b/src/parser/shell_expand/words/methods/strings.rs @@ -148,7 +148,7 @@ impl<'a> StringMethod<'a> { ); } } - "len" => if variable.starts_with('@') || variable.starts_with('[') { + "len" => if variable.starts_with('@') || is_array(variable) { let expanded = expand_string(variable, expand, false); output.push_str(&expanded.len().to_string()); } else if let Some(value) = expand.variable(variable, false) { diff --git a/src/parser/shell_expand/words/mod.rs b/src/parser/shell_expand/words/mod.rs index 0b6f66260f628e00e9e0b6c0e5dc653b1bac1f06..d1dc3323a6f3ca6252f250d143dbd36ff0767929 100644 --- a/src/parser/shell_expand/words/mod.rs +++ b/src/parser/shell_expand/words/mod.rs @@ -124,8 +124,12 @@ impl<'a, E: Expander + 'a> WordIterator<'a, E> { start = self.read; while let Some(character) = iterator.next() { if character == b')' { - let pattern = &self.data[start..self.read].trim(); self.read += 1; + if depth != 0 { + depth -= 1; + continue; + } + let pattern = &self.data[start..self.read - 1].trim(); return if let Some(&b'[') = self.data.as_bytes().get(self.read) { @@ -144,6 +148,11 @@ impl<'a, E: Expander + 'a> WordIterator<'a, E> { selection: Select::All, }) }; + } else if character == b'(' { + depth += 1; + } else if character == b'\\' { + self.read += 1; + let _ = iterator.next(); } self.read += 1; }