diff --git a/src/log-utils.cc b/src/log-utils.cc index 6d7b6848fb..78fc46edf5 100644 --- a/src/log-utils.cc +++ b/src/log-utils.cc @@ -170,17 +170,19 @@ void Log::MessageBuilder::AppendStringPart(const char* str, int len) { void Log::MessageBuilder::AppendCharacter(char c) { OFStream& os = log_->os_; - // A log entry (separate by commas) cannot contain commas or line-brakes. + // A log entry (separate by commas) cannot contain commas or line-breaks. if (c >= 32 && c <= 126) { if (c == ',') { - // Escape commas directly. + // Escape commas (log field separator) directly. os << "\x2c"; } else { // Directly append any printable ascii character. os << c; } + } else if (c == '\n') { + os << "\\n"; } else { - // Escape any non-printable haracters. + // Escape any non-printable characters. Append("\\x%02x", c); } } diff --git a/tools/csvparser.js b/tools/csvparser.js index f2c278bda8..f0f8680cf8 100644 --- a/tools/csvparser.js +++ b/tools/csvparser.js @@ -46,16 +46,21 @@ class CsvParser { while (nextPos !== -1) { let escapeIdentifier = string.charAt(nextPos + 1); pos = nextPos + 2; - if (escapeIdentifier == 'x') { - // \x00 ascii range escapes consume 2 chars. - nextPos = pos + 2; + if (escapeIdentifier == 'n') { + result += '\n'; + nextPos = pos; } else { - // \u0000 unicode range escapes consume 4 chars. - nextPos = pos + 4; + if (escapeIdentifier == 'x') { + // \x00 ascii range escapes consume 2 chars. + nextPos = pos + 2; + } else { + // \u0000 unicode range escapes consume 4 chars. + nextPos = pos + 4; + } + // Convert the selected escape sequence to a single character. + let escapeChars = string.substring(pos, nextPos); + result += String.fromCharCode(parseInt(escapeChars, 16)); } - // Convert the selected escape sequence to a single character. - let escapeChars = string.substring(pos, nextPos); - result += String.fromCharCode(parseInt(escapeChars, 16)); // Continue looking for the next escape sequence. pos = nextPos;