1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

Encode into b64 to avoid illegal xml encoding when sending to Azure (#1425)

* Encode into b64 to avoid illegal xml encoding when sending to Azure

* Revert "Encode into b64 to avoid illegal xml encoding when sending to Azure"

This reverts commit d50de941da.

* HtmlEncode strings if they use multi-byte characters

* Add serializer to event processor

* Rename to used class

* Formatting

* PR feedback
This commit is contained in:
Matt Gibson
2021-07-02 17:11:33 -04:00
committed by GitHub
parent 7cfa54ba14
commit 2c9a5bb4ab
4 changed files with 63 additions and 19 deletions

View File

@ -0,0 +1,35 @@
using System;
using Newtonsoft.Json;
namespace Bit.Core.Utilities
{
public class EncodedStringConverter : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(string);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return existingValue;
}
var value = reader.Value as string;
return System.Net.WebUtility.HtmlDecode(value);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
{
if (serializer.NullValueHandling == NullValueHandling.Include)
{
writer.WriteNull();
}
return;
}
writer.WriteValue(System.Net.WebUtility.HtmlEncode((string)value));
}
}
}