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:
35
src/Core/Utilities/EncodedStringConverter.cs
Normal file
35
src/Core/Utilities/EncodedStringConverter.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user