Browse Source

Fix completion for strings with spaces

Serj Kalichev 3 months ago
parent
commit
3de2506706
3 changed files with 2 additions and 26 deletions
  1. 0 1
      src/klish_plugin_sysrepo.h
  2. 1 24
      src/kly.c
  3. 1 1
      src/pline.c

+ 0 - 1
src/klish_plugin_sysrepo.h

@@ -330,7 +330,6 @@ bool_t klysc_node_ext(const struct lysc_node *node,
 bool_t klysc_node_ext_is_password(const struct lysc_node *node);
 const char *klysc_node_ext_completion(const struct lysc_node *node);
 const char *klysc_node_ext_default(const struct lysc_node *node);
-char *klyd_esc_value(const char *value);
 char *klyd_node_value(const struct lyd_node *node);
 const struct lysc_node *klysc_find_child(const struct lysc_node *node,
 	const char *name);

+ 1 - 24
src/kly.c

@@ -140,29 +140,6 @@ const char *klysc_node_ext_default(const struct lysc_node *node)
 }
 
 
-char *klyd_esc_value(const char *value)
-{
-	char *space = NULL;
-	char *escaped = NULL;
-	char *result = NULL;
-
-	if (!value)
-		return NULL;
-
-	escaped = faux_str_c_esc(value);
-	// String with space must have quotes
-	space = strchr(escaped, ' ');
-	if (space) {
-		result = faux_str_sprintf("\"%s\"", escaped);
-		faux_str_free(escaped);
-	} else {
-		result = escaped;
-	}
-
-	return result;
-}
-
-
 // Get value from data lyd node
 char *klyd_node_value(const struct lyd_node *node)
 {
@@ -191,7 +168,7 @@ char *klyd_node_value(const struct lyd_node *node)
 		origin_value = value->ident->name;
 	}
 
-	return klyd_esc_value(origin_value);
+	return faux_str_c_esc_quote(origin_value);
 }
 
 

+ 1 - 1
src/pline.c

@@ -1338,7 +1338,7 @@ void pline_print_completions(const pline_t *pline, bool_t help,
 					char *esc_tmp = NULL;
 					if (!tmp)
 						continue;
-					esc_tmp = klyd_esc_value(tmp);
+					esc_tmp = faux_str_c_esc_space(tmp);
 					free(tmp);
 					printf("%s\n", esc_tmp);
 					free(esc_tmp);