diff src/c/lacweb.c @ 135:b1cfe49ce692

Proper escaping of cdata
author Adam Chlipala <adamc@hcoop.net>
date Thu, 17 Jul 2008 13:33:56 -0400
parents 6230bdd122e7
children 133fa2d51bb4
line wrap: on
line diff
--- a/src/c/lacweb.c	Thu Jul 17 13:12:16 2008 -0400
+++ b/src/c/lacweb.c	Thu Jul 17 13:33:56 2008 -0400
@@ -72,6 +72,7 @@
   lw_write_unsafe(ctx, s);
 }
 
+
 char *lw_Basis_attrifyInt(lw_Basis_int n) {
   return "0";
 }
@@ -207,3 +208,33 @@
 lw_Basis_string lw_unurlifyString(char **s) {
   return "";
 }
+
+
+char *lw_Basis_htmlifyString(lw_Basis_string s) {
+  return "";
+}
+
+void lw_Basis_htmlifyString_w(lw_context ctx, lw_Basis_string s) {
+  lw_check(ctx, strlen(s) * 5);
+
+  for (; *s; s++) {
+    char c = *s;
+
+    switch (c) {
+    case '<':
+      lw_write_unsafe(ctx, "&lt;");
+      break;
+    case '&':
+      lw_write_unsafe(ctx, "&amp;");
+      break;
+    default:
+      if (isprint(c))
+        lw_writec_unsafe(ctx, c);
+      else {
+        lw_write_unsafe(ctx, "&#");
+        lw_Basis_attrifyInt_w_unsafe(ctx, c);
+        lw_writec_unsafe(ctx, ';');
+      }
+    }
+  }
+}