Browse Source

Fix escaping. Don't decode \n etc. Add \" to default escaping

git-svn-id: https://klish.googlecode.com/svn/trunk@537 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
b9521ba5e1
2 changed files with 12 additions and 9 deletions
  1. 9 7
      clish/shell/shell_var.c
  2. 3 2
      lub/string/string_escape.c

+ 9 - 7
clish/shell/shell_var.c

@@ -212,6 +212,7 @@ static char *expand_nextsegment(const char **string, const char *escape_chars,
 				int mod_quote = 0; /* quote modifier */
 				int mod_esc = 0; /* escape modifier */
 				char *space;
+				char *all_esc = NULL;
 
 				/* Search for modifiers */
 				while (*q && !isalpha(*q)) {
@@ -240,18 +241,19 @@ static char *expand_nextsegment(const char **string, const char *escape_chars,
 					lub_string_cat(&result, "\"");
 
 				/* Internal escaping */
-				if (mod_esc) {
-					char *tstr = lub_string_encode(var,
+				if (mod_esc)
+					lub_string_cat(&all_esc,
 						lub_string_esc_quoted);
-					lub_string_free(var);
-					var = tstr;
-				}
 
 				/* Escape special chars */
-				if (escape_chars) {
-					char *tstr = lub_string_encode(var, escape_chars);
+				if (escape_chars)
+					lub_string_cat(&all_esc, escape_chars);
+				if (all_esc) {
+					char *tstr = lub_string_encode(var,
+						all_esc);
 					lub_string_free(var);
 					var = tstr;
+					lub_string_free(all_esc);
 				}
 
 				/* copy the expansion or the raw word */

+ 3 - 2
lub/string/string_escape.c

@@ -6,7 +6,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-const char *lub_string_esc_default = "`|$<>&()#;";
+const char *lub_string_esc_default = "`|$<>&()#;\\\"";
 const char *lub_string_esc_regex = "^$.*+[](){}";
 const char *lub_string_esc_quoted = "\\\"";
 
@@ -30,7 +30,7 @@ char *lub_string_ndecode(const char *string, unsigned int len)
 			else
 				*p = *s;
 		} else {
-			switch (*s) {
+/*			switch (*s) {
 			case 'r':
 			case 'n':
 				*p = '\n';
@@ -42,6 +42,7 @@ char *lub_string_ndecode(const char *string, unsigned int len)
 				*p = *s;
 				break;
 			}
+*/			*p = *s;
 			esc = 0;
 		}
 		if (!esc)