Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c89ec924 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Fix btclient tokenization

Using String.split(" ") will get empty strings as tokens as well, for
example in the case of "adapter     show". This fixes this by removing
the empty strings from tokens.

Bug: 238572622
Tag: #floss
Test: Manual - Ran btclient

Change-Id: I24cac5853e09b93625464f134e9c5fbd34d733cd
parent 309861c8
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -84,10 +84,17 @@ impl BtHelper {
        let mut result = HashSet::<CommandCandidate>::new();

        for rule in self.command_rules.iter() {
            for (i, (rule_token, cmd_token)) in rule.split(" ").zip(cmd.split(" ")).enumerate() {
            let n_splits = cmd.split(" ").count();
            // The tokens should have empty strings removed from them, except the last one.
            let tokens = cmd
                .split(" ")
                .enumerate()
                .filter_map(|(i, token)| (i == n_splits - 1 || token != "").then(|| token));

            let n_cmd = tokens.clone().count();
            for (i, (rule_token, cmd_token)) in rule.split(" ").zip(tokens).enumerate() {
                let mut candidates = Vec::<String>::new();
                let mut match_some = false;
                let n_cmd = cmd.split(" ").count();

                for opt in rule_token.replace("<", "").replace(">", "").split("|") {
                    if opt.eq("address") {
+3 −4
Original line number Diff line number Diff line
@@ -570,15 +570,14 @@ async fn start_interactive_shell(
                    break;
                }
                Ok(line) => {
                    let command_vec =
                        line.split(" ").map(|s| String::from(s)).collect::<Vec<String>>();
                    let cmd = &command_vec[0];
                    let mut args = line.split_whitespace();
                    let cmd = args.next().unwrap_or("");
                    if cmd.eq("quit") {
                        break;
                    }
                    handler.process_cmd_line(
                        &String::from(cmd),
                        &command_vec[1..command_vec.len()].to_vec(),
                        &args.map(String::from).collect::<Vec<String>>(),
                    );
                    // Ready to do readline again.
                    semaphore_fg.add_permits(1);