Skip to content

Commit cbd24b5

Browse files
authored
Always allow backtick in title, summary and body (#1726)
* Always allow backtick in title, even tho it could interpreted as markdown anotation for text as code * Also allow backticks in body * Allow ambigous use of ` in message body * Fix issue with html code block and still suppot ambigous backticks
1 parent a9799da commit cbd24b5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Altinn.Correspondence.Common/Helpers/TextValidation.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ public static string ConvertToHtml(string markdown)
1818

1919
public static bool ValidatePlainText(string text)
2020
{
21+
// Ignore backticks in the comparison so backticks are always accepted.
22+
var normalizedInput = text.Replace("`", "");
2123
var converter = new ReverseMarkdown.Converter();
22-
var markdown = converter.Convert(text);
24+
var markdown = converter.Convert(normalizedInput);
2325
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
2426
var plaintext = Markdown.ToPlainText(markdown, pipeline);
25-
return plaintext.Trim() == text.Trim();
27+
return plaintext.Trim() == normalizedInput.Trim();
2628
}
2729

2830
public static bool ValidateMarkdown(string markdown)
@@ -41,8 +43,9 @@ public static bool ValidateMarkdown(string markdown)
4143
var text = WebUtility.HtmlDecode(WebUtility.HtmlDecode(markdown));
4244
result = WebUtility.HtmlDecode(WebUtility.HtmlDecode(result));
4345

44-
//As reversemarkdown makes all code blocks to ` we need to replace ``` with ` and `` with ` to compare the strings
45-
return ReplaceWhitespaceAndEscapeCharacters(text.Replace("```", "`").Replace("``", "`")) == ReplaceWhitespaceAndEscapeCharacters(result.Replace("```", "`").Replace("``", "`"));
46+
// Ignore backticks in the comparison so backticks are always accepted.
47+
// This is to make the validation consistent with how we allow ambiguous use of * and _ in markdown (lenient markdown validation).
48+
return ReplaceWhitespaceAndEscapeCharacters(text.Replace("`", "")) == ReplaceWhitespaceAndEscapeCharacters(result.Replace("`", ""));
4649
}
4750

4851
public static string ReplaceWhitespaceAndEscapeCharacters(string text)

0 commit comments

Comments
 (0)