From 2071f30a1c42dd88d94be1d350da5402966e7a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 2 Nov 2016 20:24:41 +0100 Subject: [PATCH] Remove public HTML escaping declarations from log module. --- source/vibe/core/log.d | 72 +++++++----------------------------------- 1 file changed, 11 insertions(+), 61 deletions(-) diff --git a/source/vibe/core/log.d b/source/vibe/core/log.d index 32be0be..580a366 100644 --- a/source/vibe/core/log.d +++ b/source/vibe/core/log.d @@ -520,72 +520,22 @@ final class HTMLLogger : Logger { `); m_logFile.flush(); } -} - -/** Helper stuff. -*/ -/** Writes the HTML escaped version of a given string to an output range. -*/ -void filterHTMLEscape(R, S)(ref R dst, S str, HTMLEscapeFlags flags = HTMLEscapeFlags.escapeNewline) - if (isOutputRange!(R, dchar) && isInputRange!S) -{ - for (;!str.empty;str.popFront()) - filterHTMLEscape(dst, str.front, flags); -} - -/** - Writes the HTML escaped version of a character to an output range. -*/ -void filterHTMLEscape(R)(ref R dst, dchar ch, HTMLEscapeFlags flags = HTMLEscapeFlags.escapeNewline ) -{ - switch (ch) { - default: - if (flags & HTMLEscapeFlags.escapeUnknown) { - dst.put("&#"); - dst.put(to!string(cast(uint)ch)); - dst.put(';'); - } else dst.put(ch); - break; - case '"': - if (flags & HTMLEscapeFlags.escapeQuotes) dst.put("""); - else dst.put('"'); - break; - case '\'': - if (flags & HTMLEscapeFlags.escapeQuotes) dst.put("'"); - else dst.put('\''); - break; - case '\r', '\n': - if (flags & HTMLEscapeFlags.escapeNewline) { - dst.put("&#"); - dst.put(to!string(cast(uint)ch)); - dst.put(';'); - } else dst.put(ch); - break; - case 'a': .. case 'z': goto case; - case 'A': .. case 'Z': goto case; - case '0': .. case '9': goto case; - case ' ', '\t', '-', '_', '.', ':', ',', ';', - '#', '+', '*', '?', '=', '(', ')', '/', '!', - '%' , '{', '}', '[', ']', '`', 'ยด', '$', '^', '~': - dst.put(cast(char)ch); - break; - case '<': dst.put("<"); break; - case '>': dst.put(">"); break; - case '&': dst.put("&"); break; + private static void filterHTMLEscape(R, S)(ref R dst, S str) + { + for (;!str.empty;str.popFront()) { + auto ch = str.front; + switch (ch) { + default: dst.put(ch); break; + case '<': dst.put("<"); break; + case '>': dst.put(">"); break; + case '&': dst.put("&"); break; + } + } } } -enum HTMLEscapeFlags { - escapeMinimal = 0, - escapeQuotes = 1<<0, - escapeNewline = 1<<1, - escapeUnknown = 1<<2 -} -/***************************** -*/ - import std.conv; /** A logger that logs in syslog format according to RFC 5424.