1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-13 17:26:08 +03:00

fix(edit logging): sanitize input text

This commit is contained in:
Octol1ttle 2023-10-12 21:36:37 +05:00
parent e6f53b13f0
commit 2359feca7d
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
2 changed files with 15 additions and 3 deletions

View file

@ -12,17 +12,17 @@ public static class DiffPaneModelExtensions
{
if (line.Type is ChangeType.Deleted)
{
builder.Append("- ");
builder.Append("-- ");
}
if (line.Type is ChangeType.Inserted)
{
builder.Append("+ ");
builder.Append("++ ");
}
if (line.Type is not ChangeType.Imaginary)
{
builder.AppendLine(line.Text);
builder.AppendLine(line.Text.SanitizeForDiffBlock());
}
}

View file

@ -16,6 +16,18 @@ public static class StringExtensions
return s.Replace("```", "```");
}
/// <summary>
/// Sanitizes a string for use in <see cref="Markdown.BlockCode(string, string)" /> when "language" is "diff" by
/// prepending a zero-width space before syntax highlighting characters (+ and -).
/// </summary>
/// <remarks>This does not call <see cref="SanitizeForBlockCode"/>, you have to do so yourself if needed.</remarks>
/// <param name="s">The string to sanitize.</param>
/// <returns>The sanitized string that can be safely used in <see cref="Markdown.BlockCode(string, string)" /> with "diff" as the language.</returns>
public static string SanitizeForDiffBlock(this string s)
{
return $"{s}";
}
/// <summary>
/// Sanitizes a string (see <see cref="SanitizeForBlockCode" />) and formats the string to use Markdown Block Code
/// formatting with a specified