Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extending TeamCity service message escaping coding

  • Loading branch information...
commit ce51cccb5a13d12f4cd3515a305b561f721799cc 1 parent ac45687
@agross agross authored
View
64 ...e/Machine.Specifications.Reporting.Specs/Integration/TeamCityServiceMessageWriterSpecs.cs
@@ -2,26 +2,46 @@
namespace Machine.Specifications.Reporting.Specs.Integration
{
- [Subject(typeof(TeamCityServiceMessageWriter))]
- public class when_errors_are_reported
- {
- Establish context = () =>
- {
- Writer = new TeamCityServiceMessageWriter(s => Written = s);
- };
-
- Because of = () => Writer.WriteError("test failed", "details");
-
- It should_report_an_error_string =
- () => Written.ShouldEndWith("status=\'ERROR\']");
-
- It should_report_the_error_message =
- () => { Written.ShouldContain("test=\'test failed\'"); };
-
- It should_report_error_details =
- () => { Written.ShouldContain("errorDetails=\'details\'"); };
-
- static string Written;
- static TeamCityServiceMessageWriter Writer;
- }
+ [Subject(typeof(TeamCityServiceMessageWriter))]
+ public class when_errors_are_reported
+ {
+ static string Written;
+ static TeamCityServiceMessageWriter Writer;
+
+ Establish context = () => { Writer = new TeamCityServiceMessageWriter(s => Written = s); };
+
+ Because of = () => Writer.WriteError("test failed", "details");
+
+ It should_report_an_error_string =
+ () => Written.ShouldEndWith("status=\'ERROR\']");
+
+ It should_report_the_error_message =
+ () => { Written.ShouldContain("test=\'test failed\'"); };
+
+ It should_report_error_details =
+ () => { Written.ShouldContain("errorDetails=\'details\'"); };
+ }
+
+ [Subject(typeof(TeamCityServiceMessageWriter))]
+ public class when_special_characters_are_used
+ {
+ static string Written;
+ static TeamCityServiceMessageWriter Writer;
+
+ Establish context = () => { Writer = new TeamCityServiceMessageWriter(s => Written = s); };
+
+ Because of =
+ () => Writer.WriteTestFailed("Name abc | ' \n \r ] \u0085 \u2028 \u2029",
+ "Message abc | ' \n \r ] \u0085 \u2028 \u2029",
+ "Details abc | ' \n \r ] \u0085 \u2028 \u2029");
+
+ It should_escape_special__name__characters =
+ () => Written.ShouldContain("Name abc || |' |n |r |] |x |l |p");
+
+ It should_escape_special__message__characters =
+ () => Written.ShouldContain("Message abc || |' |n |r |] |x |l |p");
+
+ It should_escape_special__details__characters =
+ () => Written.ShouldContain("Details abc || |' |n |r |] |x |l |p");
+ }
}
View
44 Source/Machine.Specifications.Reporting/Integration/TeamCityServiceMessageWriter.cs
@@ -256,21 +256,39 @@ private void WriteMessage(Action<StringBuilder> formatter)
private static void AppendEscapedString(StringBuilder builder, string rawString)
{
- foreach (char c in rawString)
+ foreach (char c in rawString)
+ {
+ switch (c)
{
- if (c == '\n')
- builder.Append("|n");
- else if (c == '\'')
- builder.Append("|'");
- else if (c == '\r')
- builder.Append("|r");
- else if (c == '|')
- builder.Append("||");
- else if (c == ']')
- builder.Append("|]");
- else
- builder.Append(c);
+ case '\n':
+ builder.Append("|n");
+ break;
+ case '\'':
+ builder.Append("|'");
+ break;
+ case '\r':
+ builder.Append("|r");
+ break;
+ case '|':
+ builder.Append("||");
+ break;
+ case ']':
+ builder.Append("|]");
+ break;
+ case '\u0085': // \u0085 (next line) => |x
+ builder.Append("|x");
+ break;
+ case '\u2028': // \u2028 (line separator) => |l
+ builder.Append("|l");
+ break;
+ case '\u2029':
+ builder.Append("|p");
+ break;
+ default:
+ builder.Append(c);
+ break;
}
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.