Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Unify encoding to be Strict UTF8 (#639)
Browse files Browse the repository at this point in the history
* Strict UTF8

* Clean usings
  • Loading branch information
shargon authored Aug 5, 2020
1 parent fb2f997 commit bb07347
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions neo-cli/CLI/MainService.Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;

namespace Neo.CLI
{
Expand Down Expand Up @@ -70,7 +69,7 @@ private string HexToString(string hexString)
{
var clearHexString = ClearHexString(hexString);
var bytes = clearHexString.HexToBytes();
var utf8String = Encoding.UTF8.GetString(bytes);
var utf8String = Utility.StrictUTF8.GetString(bytes);

if (!IsPrintable(utf8String))
{
Expand Down Expand Up @@ -170,7 +169,7 @@ private string StringToHex(string strParam)
{
try
{
var bytesParam = Encoding.UTF8.GetBytes(strParam);
var bytesParam = Utility.StrictUTF8.GetBytes(strParam);
return bytesParam.ToHexString();
}
catch
Expand All @@ -196,7 +195,7 @@ private string StringToBase64(string strParam)
{
try
{
byte[] bytearray = Encoding.UTF8.GetBytes(strParam);
byte[] bytearray = Utility.StrictUTF8.GetBytes(strParam);
string base64 = Convert.ToBase64String(bytearray.AsSpan());
return base64;
}
Expand Down Expand Up @@ -407,7 +406,7 @@ private string Base64ToString(string bytearray)
try
{
byte[] result = Convert.FromBase64String(bytearray);
string utf8string = Encoding.UTF8.GetString(result);
string utf8string = Utility.StrictUTF8.GetString(result);

if (!IsPrintable(utf8string))
{
Expand Down
3 changes: 1 addition & 2 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

Expand Down Expand Up @@ -263,7 +262,7 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,
}

NefFile file;
using (var stream = new BinaryReader(File.OpenRead(nefFilePath), Encoding.UTF8, false))
using (var stream = new BinaryReader(File.OpenRead(nefFilePath), Utility.StrictUTF8, false))
{
file = stream.ReadSerializable<NefFile>();
}
Expand Down

0 comments on commit bb07347

Please sign in to comment.