Skip to content

Commit

Permalink
fixes #29095, machine mode escapes newline/returns
Browse files Browse the repository at this point in the history
R=skybrian@google.com

Review-Url: https://codereview.chromium.org/2770493003 .
  • Loading branch information
Jennifer Messerly committed Mar 22, 2017
1 parent de54e18 commit f3f814b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/analyzer_cli/lib/src/error_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class AnalysisStats {
class ErrorFormatter {
static final int _pipeCodeUnit = '|'.codeUnitAt(0);
static final int _slashCodeUnit = '\\'.codeUnitAt(0);
static final int _newline = '\n'.codeUnitAt(0);
static final int _return = '\r'.codeUnitAt(0);

final StringSink out;
final CommandLineOptions options;
Expand Down Expand Up @@ -144,15 +146,15 @@ class ErrorFormatter {
out.write('|');
out.write(error.errorCode.name);
out.write('|');
out.write(escapePipe(source.fullName));
out.write(escapeForMachineMode(source.fullName));
out.write('|');
out.write(location.lineNumber);
out.write('|');
out.write(location.columnNumber);
out.write('|');
out.write(length);
out.write('|');
out.write(escapePipe(error.message));
out.write(escapeForMachineMode(error.message));
out.writeln();
} else {
// Get display name.
Expand Down Expand Up @@ -252,13 +254,19 @@ class ErrorFormatter {
}
}

static String escapePipe(String input) {
static String escapeForMachineMode(String input) {
StringBuffer result = new StringBuffer();
for (int c in input.codeUnits) {
if (c == _slashCodeUnit || c == _pipeCodeUnit) {
result.write('\\');
if (c == _newline) {
result.write(r'\n');
} else if (c == _return) {
result.write(r'\r');
} else {
if (c == _slashCodeUnit || c == _pipeCodeUnit) {
result.write('\\');
}
result.writeCharCode(c);
}
result.writeCharCode(c);
}
return result.toString();
}
Expand Down

0 comments on commit f3f814b

Please sign in to comment.