Skip to content

Commit

Permalink
Add exception to QuotedPrintable. (#2237)
Browse files Browse the repository at this point in the history
* Add exception to QuotedPrintable.

* Extended enum FileLogger.Format

* Removed trailing whitespace
  • Loading branch information
Tusanga authored and s-ludwig committed Dec 26, 2018
1 parent 056a9a9 commit 15ccde8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/vibe/core/log.d
Expand Up @@ -246,7 +246,9 @@ final class FileLogger : Logger {
/// The log format used by the FileLogger
enum Format {
plain, /// Output only the plain log message
level, /// Prefix "[loglevel]"
thread, /// Prefix "[thread-id:fiber-id loglevel]"
timeLevel, /// Prefix "[timestamp loglevel]"
threadTime /// Prefix "[thread-id:fiber-id timestamp loglevel]"
}

Expand Down Expand Up @@ -292,7 +294,16 @@ final class FileLogger : Logger {

final switch (fmt) {
case Format.plain: break;
case Format.level: m_curFile.writef("[%s] ", pref); break;
case Format.thread: m_curFile.writef("[%08X:%08X %s] ", msg.threadID, msg.fiberID, pref); break;
case Format.timeLevel:
auto tm = msg.time;
static if (is(typeof(tm.fracSecs))) auto msecs = tm.fracSecs.total!"msecs";
else auto msecs = tm.fracSec.msecs;
m_curFile.writef("[%d.%02d.%02d %02d:%02d:%02d.%03d %s] ",
tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second, msecs,
pref);
break;
case Format.threadTime:
auto tm = msg.time;
static if (is(typeof(tm.fracSecs))) auto msecs = tm.fracSecs.total!"msecs";
Expand All @@ -317,6 +328,21 @@ final class FileLogger : Logger {
}
}

unittest
{
logError("Default");
setLogFormat(FileLogger.Format.plain);
logError("Plain");
setLogFormat(FileLogger.Format.level);
logError("Level");
setLogFormat(FileLogger.Format.thread);
logError("Thread");
setLogFormat(FileLogger.Format.timeLevel);
logError("TimeLevel");
setLogFormat(FileLogger.Format.threadTime);
logError("ThreadTime");
}

/**
Logger implementation for logging to an HTML file with dynamic filtering support.
*/
Expand Down
12 changes: 12 additions & 0 deletions inet/vibe/inet/message.d
Expand Up @@ -361,6 +361,8 @@ struct QuotedPrintable {
auto ret = appender!(ubyte[])();
for( size_t i = 0; i < input.length; i++ ){
if( input[i] == '=' ){
import std.utf : UTFException;
if (input.length - i <= 2) throw new UTFException("");
auto code = input[i+1 .. i+3];
i += 2;
if( code != cast(const(ubyte)[])"\r\n" )
Expand All @@ -372,6 +374,16 @@ struct QuotedPrintable {
}
}

unittest
{
assert(QuotedPrintable.decode("abc") == "abc");
assert(QuotedPrintable.decode("a=3Cc") == "a<c");

import std.exception;
import std.utf : UTFException;
assertThrown!UTFException(QuotedPrintable.decode("ab=c"));
assertThrown!UTFException(QuotedPrintable.decode("abc="));
}


private void writeDecimal2(R)(ref R dst, uint n)
Expand Down

0 comments on commit 15ccde8

Please sign in to comment.