Commit e4a97a2e authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[log] Escape newline with \n

Change-Id: I456b3456351860e3e5e7e9dcb800d42d543a7c47
Reviewed-on: https://chromium-review.googlesource.com/753681
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49110}
parent cc557479
......@@ -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);
}
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment