aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Trinkala2023-02-01 22:07:42 +0000
committerGitHub2023-02-01 22:07:42 +0000
commit62d046fa219b927c536bf6726fcae1e825346e0e (patch)
treec44e979f110449d6e023dba2f23ed96bf430b6ce
parent685cd383a3a56755b06b4146d5dc14872890a56e (diff)
Fix utf8 length handling for shellwords (#5738)
If the last argument to shellwords ends in a multibyte utf8 character the entire argument will be dropped. e.g. `:sh echo test1 test2π’€€` will only output `test1` Add additional tests based on the code review feedback
-rw-r--r--helix-core/src/shellwords.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/helix-core/src/shellwords.rs b/helix-core/src/shellwords.rs
index 9475f5e5..0883eb91 100644
--- a/helix-core/src/shellwords.rs
+++ b/helix-core/src/shellwords.rs
@@ -129,8 +129,9 @@ impl<'a> From<&'a str> for Shellwords<'a> {
DquoteEscaped => Dquoted,
};
- if i >= input.len() - 1 && end == 0 {
- end = i + 1;
+ let c_len = c.len_utf8();
+ if i == input.len() - c_len && end == 0 {
+ end = i + c_len;
}
if end > 0 {
@@ -333,4 +334,17 @@ mod test {
assert_eq!(Shellwords::from(":o a").parts(), &[":o", "a"]);
assert_eq!(Shellwords::from(":o a\\ ").parts(), &[":o", "a\\"]);
}
+
+ #[test]
+ fn test_multibyte_at_end() {
+ assert_eq!(Shellwords::from("π’€€").parts(), &["π’€€"]);
+ assert_eq!(
+ Shellwords::from(":sh echo π’€€").parts(),
+ &[":sh", "echo", "π’€€"]
+ );
+ assert_eq!(
+ Shellwords::from(":sh echo π’€€ hello worldπ’€€").parts(),
+ &[":sh", "echo", "π’€€", "hello", "worldπ’€€"]
+ );
+ }
}