Repository: paulgazz/kmax (language: python)

Issue:
Escape characters lost in kextract output
When a default value has an escape character, such as:
```
config CONFIG_VISUAL_STUDIO_7_0_BASE
    string "Base"
    depends on CONFIG_VISUAL_STUDIO_7_0
    default "c:\\Program Files\\Microsoft Visual Studio .NET 2003"
```
The output strips away the escape:
`def_nonbool CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE "c:\Program Files\Microsoft Visual Studio .NET 2003"`


Discussion / hints:

Fix patch:
diff --git a/kextractors/kextractor-3.19/kextractor.c b/kextractors/kextractor-3.19/kextractor.c
index 39ebe024..e0ae0fb8 100644
--- a/kextractors/kextractor-3.19/kextractor.c
+++ b/kextractors/kextractor-3.19/kextractor.c
@@ -326,7 +326,7 @@ void print_python_symbol_detail(FILE *out, struct symbol *sym, bool force_naked)
     } else if (strcmp(sym->name, "n") == 0) {
       fprintf(out, "0");
     } else if (S_UNKNOWN == sym->type) {
-      fprintf(out, "\"%s\"", sym->name);
+      fprintf(out, "%s", sym_escape_string_value(sym->name));
     } else {
       if (! force_naked) {
         fprintf(out, "%s%s", config_prefix, sym->name);
diff --git a/kextractors/kextractor-4.12.8/kextractor.c b/kextractors/kextractor-4.12.8/kextractor.c
index d4be46bd..4eb3cb27 100644
--- a/kextractors/kextractor-4.12.8/kextractor.c
+++ b/kextractors/kextractor-4.12.8/kextractor.c
@@ -326,7 +326,7 @@ void print_python_symbol_detail(FILE *out, struct symbol *sym, bool force_naked)
     } else if (strcmp(sym->name, "n") == 0) {
       fprintf(out, "0");
     } else if (S_UNKNOWN == sym->type) {
-      fprintf(out, "\"%s\"", sym->name);
+      fprintf(out, "%s", sym_escape_string_value(sym->name));
     } else {
       if (! force_naked) {
         fprintf(out, "%s%s", config_prefix, sym->name);
diff --git a/kextractors/kextractor-4.18/kextractor.c b/kextractors/kextractor-4.18/kextractor.c
index 116cf981..58655b0e 100644
--- a/kextractors/kextractor-4.18/kextractor.c
+++ b/kextractors/kextractor-4.18/kextractor.c
@@ -264,7 +264,7 @@ void print_python_symbol_detail(FILE *out, struct symbol *sym, bool force_naked)
     } else if (strcmp(sym->name, "n") == 0) {
       fprintf(out, "0");
     } else if (S_UNKNOWN == sym->type) {
-      fprintf(out, "\"%s\"", sym->name);
+      fprintf(out, "%s", sym_escape_string_value(sym->name));
     } else {
       if (! force_naked) {
         fprintf(out, "%s%s", config_prefix, sym->name);
diff --git a/kextractors/kextractor-next-20200430/kextractor.c b/kextractors/kextractor-next-20200430/kextractor.c
index 116cf981..58655b0e 100644
--- a/kextractors/kextractor-next-20200430/kextractor.c
+++ b/kextractors/kextractor-next-20200430/kextractor.c
@@ -264,7 +264,7 @@ void print_python_symbol_detail(FILE *out, struct symbol *sym, bool force_naked)
     } else if (strcmp(sym->name, "n") == 0) {
       fprintf(out, "0");
     } else if (S_UNKNOWN == sym->type) {
-      fprintf(out, "\"%s\"", sym->name);
+      fprintf(out, "%s", sym_escape_string_value(sym->name));
     } else {
       if (! force_naked) {
         fprintf(out, "%s%s", config_prefix, sym->name);
diff --git a/kextractors/kextractor-next-20210426/kextractor.c b/kextractors/kextractor-next-20210426/kextractor.c
index 9c6497fe..424111eb 100644
--- a/kextractors/kextractor-next-20210426/kextractor.c
+++ b/kextractors/kextractor-next-20210426/kextractor.c
@@ -262,7 +262,7 @@ void print_python_symbol_detail(FILE *out, struct symbol *sym, bool force_naked)
     } else if (strcmp(sym->name, "n") == 0) {
       fprintf(out, "0");
     } else if (S_UNKNOWN == sym->type) {
-      fprintf(out, "\"%s\"", sym->name);
+      fprintf(out, "%s", sym_escape_string_value(sym->name));
     } else {
       if (! force_naked) {
         fprintf(out, "%s%s", config_prefix, sym->name);


Test patch:
diff --git a/tests/kclause_tests/escape_codes b/tests/kclause_tests/escape_codes
new file mode 100644
index 00000000..a88689eb
--- /dev/null
+++ b/tests/kclause_tests/escape_codes
@@ -0,0 +1,4 @@
+config CONFIG_VISUAL_STUDIO_7_0_BASE
+    string "Base"
+    depends on CONFIG_VISUAL_STUDIO_7_0
+    default "c:\\Program Files\\Microsoft Visual Studio .NET 2003"
diff --git a/tests/kclause_tests/escape_codes.extract-3.19 b/tests/kclause_tests/escape_codes.extract-3.19
new file mode 100644
index 00000000..262e688e
--- /dev/null
+++ b/tests/kclause_tests/escape_codes.extract-3.19
@@ -0,0 +1,7 @@
+config CONFIG_UNAME_RELEASE string
+def_nonbool CONFIG_UNAME_RELEASE "5.15.0-56-generic"|(1)
+config CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE string
+prompt CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE ("CONFIG_VISUAL_STUDIO_7_0")
+def_nonbool CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE "c:\\Program Files\\Microsoft Visual Studio .NET 2003"|("CONFIG_VISUAL_STUDIO_7_0")
+dep CONFIG_UNAME_RELEASE (1)
+dep CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE ("CONFIG_VISUAL_STUDIO_7_0")