Project

General

Profile

Bug #1806 ยป data_string_print_escape.patch.txt

glen, 2010-05-28 16:39

 
1
--- lighttpd-1.4.26/src/data_string.c~	2010-05-25 00:53:55.000000000 +0300
2
+++ lighttpd-1.4.26/src/data_string.c	2010-05-25 00:53:59.407739779 +0300
3
@@ -70,8 +70,19 @@
4
 static void data_string_print(const data_unset *d, int depth) {
5
 	data_string *ds = (data_string *)d;
6
 	UNUSED(depth);
7
+	unsigned int i = 0;
8
 
9
-	fprintf(stdout, "\"%s\"", ds->value->used ? ds->value->ptr : "");
10
+	// print out the string as is, except prepend " with backslash
11
+	putc('"', stdout);
12
+	for (i = 0; i < ds->value->used - 1; i++) {
13
+		unsigned char c = ds->value->ptr[i];
14
+		if (c == '"') {
15
+			fputs("\\\"", stdout);
16
+		} else {
17
+			putc(c, stdout);
18
+		}
19
+	}
20
+	putc('"', stdout);
21
 }
22
 
23
 
    (1-1/1)