Repository: neovim/neovim
File: src/nvim/api/command.c (C)

Code before:
  Dict(cmd) result = KEYDICT_INIT;

  // Parse command line
  exarg_T ea;
  CmdParseInfo cmdinfo;
  char *cmdline = arena_memdupz(arena, str.data, str.size);
  const char *errormsg = NULL;

  if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) {
    if (errormsg != NULL) {
      api_set_error(err, kErrorTypeException, "Parsing command-line: %s", errormsg);
    } else {
      api_set_error(err, kErrorTypeException, "Parsing command-line");
    }
    goto end;
  }

  // Parse arguments
  Array args = ARRAY_DICT_INIT;
  size_t length = strlen(ea.arg);

  // Check if this is a mapping command that needs special handling
  // like mapping commands need special argument parsing to preserve whitespace in RHS:
  // "map a b  c" => { args=["a", "b  c"], ... }
  bool is_mapping_cmd = is_mapping_command(ea.cmdidx);
  if (is_mapping_cmd && *ea.arg != NUL) {
    // For mapping commands, split differently to preserve whitespace
    args = parse_mapping_args(ea.arg, arena);
  } else if (ea.argt & EX_NOSPC) {
    // For nargs = 1 or '?', pass the entire argument list as a single argument,
    // otherwise split arguments by whitespace.
    if (*ea.arg != NUL) {
      args = arena_array(arena, 1);
      ADD_C(args, STRING_OBJ(cstrn_as_string(ea.arg, length)));
    }
  } else {
    size_t end = 0;
    size_t len = 0;
    char *buf = arena_alloc(arena, length + 1, false);
    bool done = false;
    args = arena_array(arena, uc_nargs_upper_bound(ea.arg, length));

    while (!done) {
      done = uc_split_args_iter(ea.arg, length, &end, buf, &len);
      if (len > 0) {
        ADD_C(args, STRING_OBJ(cstrn_as_string(buf, len)));
        buf += len + 1;
      }
    }
  }


Review comment (suggestion):
```suggestion
  if (is_mapping_command(ea.cmdidx) && *ea.arg != NUL) {
```

Code after:
  Dict(cmd) result = KEYDICT_INIT;

  // Parse command line
  exarg_T ea;
  CmdParseInfo cmdinfo;
  char *cmdline = arena_memdupz(arena, str.data, str.size);
  const char *errormsg = NULL;

  if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) {
    if (errormsg != NULL) {
      api_set_error(err, kErrorTypeException, "Parsing command-line: %s", errormsg);
    } else {
      api_set_error(err, kErrorTypeException, "Parsing command-line");
    }
    goto end;
  }

  // Parse arguments
  Array args = ARRAY_DICT_INIT;
  size_t length = strlen(ea.arg);

  // Check if this is a mapping command that needs special handling
  // like mapping commands need special argument parsing to preserve whitespace in RHS:
  // "map a b  c" => { args=["a", "b  c"], ... }
  if (is_map_cmd(ea.cmdidx) && *ea.arg != NUL) {
    // For mapping commands, split differently to preserve whitespace
    args = parse_map_cmd(ea.arg, arena);
  } else if (ea.argt & EX_NOSPC) {
    // For nargs = 1 or '?', pass the entire argument list as a single argument,
    // otherwise split arguments by whitespace.
    if (*ea.arg != NUL) {
      args = arena_array(arena, 1);
      ADD_C(args, STRING_OBJ(cstrn_as_string(ea.arg, length)));
    }
  } else {
    size_t end = 0;
    size_t len = 0;
    char *buf = arena_alloc(arena, length + 1, false);
    bool done = false;
    args = arena_array(arena, uc_nargs_upper_bound(ea.arg, length));

    while (!done) {
      done = uc_split_args_iter(ea.arg, length, &end, buf, &len);
      if (len > 0) {
        ADD_C(args, STRING_OBJ(cstrn_as_string(buf, len)));
        buf += len + 1;
      }
    }
  }

  ucmd_T *cmd = NULL;