Skip to content

Commit e9a026c

Browse files
committed
Refactoring of obsolete functions
1 parent 2be8b56 commit e9a026c

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

QRCoder/PayloadGenerator.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,12 @@ public BitcoinLikeCryptoCurrencyAddress(BitcoinLikeCryptoCurrencyType currencyTy
634634

635635
if (!string.IsNullOrEmpty(label))
636636
{
637-
this.label = Uri.EscapeUriString(label);
637+
this.label = Uri.EscapeDataString(label);
638638
}
639639

640640
if (!string.IsNullOrEmpty(message))
641641
{
642-
this.message = Uri.EscapeUriString(message);
642+
this.message = Uri.EscapeDataString(message);
643643
}
644644

645645
this.amount = amount;
@@ -2012,41 +2012,34 @@ private void ProcessCommonFields(StringBuilder sb)
20122012
}
20132013
string strippedSecret = Secret.Replace(" ", "");
20142014
string escapedIssuer = null;
2015-
string escapedLabel = null;
2015+
string label = null;
20162016

20172017
if (!String40Methods.IsNullOrWhiteSpace(Issuer))
20182018
{
20192019
if (Issuer.Contains(":"))
20202020
{
20212021
throw new Exception("Issuer must not have a ':'");
20222022
}
2023-
escapedIssuer = Uri.EscapeUriString(Issuer);
2023+
escapedIssuer = Uri.EscapeDataString(Issuer);
20242024
}
20252025

2026-
if (!String40Methods.IsNullOrWhiteSpace(Label))
2026+
if (!String40Methods.IsNullOrWhiteSpace(Label) && Label.Contains(":"))
20272027
{
2028-
if (Label.Contains(":"))
2029-
{
2030-
throw new Exception("Label must not have a ':'");
2031-
}
2032-
escapedLabel = Uri.EscapeUriString(Label);
2028+
throw new Exception("Label must not have a ':'");
20332029
}
20342030

2035-
if (escapedLabel != null)
2031+
if (Label != null && Issuer != null)
20362032
{
2037-
if (escapedIssuer != null)
2038-
{
2039-
escapedLabel = escapedIssuer + ":" + escapedLabel;
2040-
}
2033+
label = Issuer + ":" + Label;
20412034
}
2042-
else if (escapedIssuer != null)
2035+
else if (Issuer != null)
20432036
{
2044-
escapedLabel = escapedIssuer;
2037+
label = Issuer;
20452038
}
20462039

2047-
if (escapedLabel != null)
2040+
if (label != null)
20482041
{
2049-
sb.Append(escapedLabel);
2042+
sb.Append(label);
20502043
}
20512044

20522045
sb.Append("?secret=" + strippedSecret);

QRCoderTests/Helpers/HelperFunctions.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ public static Bitmap BitmapSourceToBitmap(DrawingImage xamlImg)
5050
public static string GetAssemblyPath()
5151
{
5252
return
53-
#if NET5_0
54-
AppDomain.CurrentDomain.BaseDirectory;
53+
#if NET5_0 || NET6_0
54+
AppDomain.CurrentDomain.BaseDirectory;
55+
#elif NET35 || NET452
56+
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "");
5557
#else
56-
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "");
58+
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).Replace("file:\\", "");
5759
#endif
5860
}
5961
#endif
@@ -76,7 +78,7 @@ public static string BitmapToHash(Bitmap bmp)
7678
public static string ByteArrayToHash(byte[] data)
7779
{
7880
#if !NETCOREAPP1_1
79-
var md5 = new MD5CryptoServiceProvider();
81+
var md5 = MD5.Create();
8082
var hash = md5.ComputeHash(data);
8183
#else
8284
var hash = new SshNet.Security.Cryptography.MD5().ComputeHash(data);

0 commit comments

Comments
 (0)