Conversation
|
Create a function in /// <summary>
/// JsonEncode the string values of the data object.
/// </summary>
/// <param name="dataObject">The data object to encode.</param>
/// <returns>The encoded data object.</returns>
public static Dictionary<string, object> JsonEncodeStrings(this Dictionary<string, object> dataObject)
{
foreach (var key in dataObject.Keys)
{
var value = dataObject[key];
if (value is string stringValue)
{
dataObject[key] = JsonEncodedText.Encode(stringValue);
}
}
return dataObject;
} |
After reviewing /// <summary>
/// Escape quotes for proper json.
/// </summary>
/// <param name="input">Input string.</param>
/// <returns>Escaped string.</returns>
public static string Escape(this string? input)
{
if (input == null)
{
return string.Empty;
}
return JsonEncodedText.Encode(input).ToString();
} |
crobibero
left a comment
There was a problem hiding this comment.
I think Escaping is different from JsonEncoding. I almost think that we would need to move this to a Handlebars function so the user can specify to encode in the template
| return string.Empty; | ||
| } | ||
|
|
||
| return JsonEncodedText.Encode(input).ToString(); |
There was a problem hiding this comment.
| return JsonEncodedText.Encode(input).ToString(); | |
| return JsonEncodedText.Encode(input).Value; |
|
Notifications that are not sent to discord. If I understand, this needs to be implemented to fix? |
In this case they're the exact same thing, assuming webhooks are always JSON and not XML, the existing
Now, if the webhook plugin can also send XML payloads (which does not seem to be the case but I fully admit I might be blind and missing it) I would say they are different things, and the second part of your suggestion might need followed up on. As it stands at the moment though in this case "Encode" and "Escape" mean the exact same thing. |
|
Yes, this plugin supports xml and any other format that someone can imagine. |
|
@crobibero I just opened a PR that should resolve some of the questions you had on this one. I would have liked to extend/modify this PR but I got my local git into such a mess that I found it easier to simply fork the whole repo myself and start fresh. |
The Discord webhook does not JSON encode the strings used in the handlebars template. So if a description has newlines, it results in invalid JSON, and does not correctly post to discord. As described in #217.
This pull request serializes all of the objects in the data dictionary with
System.Text.Json.JsonSerializer.Serializebefore rendering the template so that quotes and newlines are correctly escaped.This may be necessary for other webhook clients depending on their APIs.