Skip to content

Commit 188112f

Browse files
authored
replace SecurityHelper.AreStringTypesEqual with string.Equals for clarity (#9521)
1 parent a08882f commit 188112f

File tree

6 files changed

+19
-43
lines changed

6 files changed

+19
-43
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AppModel/SiteOfOriginPart.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System.IO;
1919
using System.Resources;
2020
using System.Globalization;
21-
using MS.Internal.PresentationCore;
2221

2322
namespace MS.Internal.AppModel
2423
{
@@ -146,7 +145,7 @@ private Stream GetStreamAndSetContentType(bool onlyNeedContentType)
146145
// For performance reasons it is better to open local files directly
147146
// rather than make a FileWebRequest.
148147
Stream responseStream;
149-
if (SecurityHelper.AreStringTypesEqual(_absoluteLocation.Scheme, Uri.UriSchemeFile))
148+
if (string.Equals(_absoluteLocation.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase))
150149
{
151150
responseStream = HandleFileSource(onlyNeedContentType);
152151
}

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Navigation/BaseUriHelper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.IO.Packaging;
1212
using System.Globalization;
1313
using System.Net;
14-
using System.Security;
1514
using System.Text;
1615
using System.Windows;
1716
using System.Windows.Markup;
@@ -153,12 +152,12 @@ internal static bool IsPackApplicationUri(Uri uri)
153152
uri.IsAbsoluteUri &&
154153

155154
// Does the "outer" URI have the pack: scheme?
156-
SecurityHelper.AreStringTypesEqual(uri.Scheme, System.IO.Packaging.PackUriHelper.UriSchemePack) &&
155+
string.Equals(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase) &&
157156

158157
// Does the "inner" URI have the application: scheme
159-
SecurityHelper.AreStringTypesEqual(
160-
PackUriHelper.GetPackageUri(uri).GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped),
161-
_packageApplicationBaseUriEscaped);
158+
string.Equals(PackUriHelper.GetPackageUri(uri).GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped),
159+
_packageApplicationBaseUriEscaped,
160+
StringComparison.OrdinalIgnoreCase);
162161
}
163162

164163
// The method accepts a relative or absolute Uri and returns the appropriate assembly.
@@ -175,7 +174,7 @@ internal static void GetAssemblyAndPartNameFromPackAppUri(Uri uri, out Assembly
175174
// The input Uri is assumed to be a valid absolute pack application Uri.
176175
// The caller should guarantee that.
177176
// Perform a sanity check to make sure the assumption stays.
178-
Debug.Assert(uri != null && uri.IsAbsoluteUri && SecurityHelper.AreStringTypesEqual(uri.Scheme, System.IO.Packaging.PackUriHelper.UriSchemePack) && IsPackApplicationUri(uri));
177+
Debug.Assert(uri is not null && uri.IsAbsoluteUri && string.Equals(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase) && IsPackApplicationUri(uri));
179178

180179
// Generate a relative Uri which gets rid of the pack://application:,,, authority part.
181180
Uri partUri = new Uri(uri.AbsolutePath, UriKind.Relative);
@@ -186,7 +185,7 @@ internal static void GetAssemblyAndPartNameFromPackAppUri(Uri uri, out Assembly
186185

187186
GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey);
188187

189-
if (String.IsNullOrEmpty(assemblyName))
188+
if (string.IsNullOrEmpty(assemblyName))
190189
{
191190
// The uri doesn't contain ";component". it should map to the enty application assembly.
192191
assembly = ResourceAssembly;
@@ -373,7 +372,7 @@ static internal Uri MakeRelativeToSiteOfOriginIfPossible(Uri sUri)
373372

374373
static internal Uri ConvertPackUriToAbsoluteExternallyVisibleUri(Uri packUri)
375374
{
376-
Invariant.Assert(packUri.IsAbsoluteUri && SecurityHelper.AreStringTypesEqual(packUri.Scheme, PackAppBaseUri.Scheme));
375+
Invariant.Assert(packUri.IsAbsoluteUri && string.Equals(packUri.Scheme, PackAppBaseUri.Scheme, StringComparison.OrdinalIgnoreCase));
377376

378377
Uri relative = MakeRelativeToSiteOfOriginIfPossible(packUri);
379378

@@ -393,7 +392,8 @@ static internal Uri ConvertPackUriToAbsoluteExternallyVisibleUri(Uri packUri)
393392
// that contains the scheme file://.
394393
static internal Uri FixFileUri(Uri uri)
395394
{
396-
if (uri != null && uri.IsAbsoluteUri && SecurityHelper.AreStringTypesEqual(uri.Scheme, Uri.UriSchemeFile) &&
395+
if (uri is not null && uri.IsAbsoluteUri &&
396+
string.Equals(uri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase) &&
397397
string.Compare(uri.OriginalString, 0, Uri.UriSchemeFile, 0, Uri.UriSchemeFile.Length, StringComparison.OrdinalIgnoreCase) != 0)
398398
{
399399
return new Uri(uri.AbsoluteUri);

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppModelKnownContentFactory.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
using System;
1111
using System.IO;
12-
using System.Security;
1312
using System.Windows;
1413
using System.Windows.Markup;
1514
using System.Windows.Navigation;
@@ -18,7 +17,6 @@
1817
using MS.Internal.Utility;
1918
using MS.Internal.Resources;
2019
using System.IO.Packaging;
21-
using MS.Internal.PresentationFramework;
2220
using System.ComponentModel;
2321
using System.Windows.Controls;
2422

@@ -81,7 +79,7 @@ internal static object XamlConverterCore(Stream stream, Uri baseUri, bool canUse
8179

8280
if (sandboxExternalContent)
8381
{
84-
if (SecurityHelper.AreStringTypesEqual(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme))
82+
if (string.Equals(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme, StringComparison.OrdinalIgnoreCase))
8583
{
8684
baseUri = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(baseUri);
8785
}
@@ -146,7 +144,7 @@ internal static object HtmlXappConverterCore(Stream stream, Uri baseUri, bool ca
146144
return null;
147145
}
148146

149-
if (SecurityHelper.AreStringTypesEqual(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme))
147+
if (string.Equals(baseUri.Scheme, BaseUriHelper.PackAppBaseUri.Scheme, StringComparison.OrdinalIgnoreCase))
150148
{
151149
baseUri = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(baseUri);
152150
}

src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/AddressUtility.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
// strings and Uri objects.
88
using System;
99
using System.Globalization;
10-
using System.Text.RegularExpressions;
11-
using MS.Internal.WindowsBase;
12-
1310

1411
namespace MS.Internal.Documents
1512
{
@@ -31,14 +28,7 @@ internal static class AddressUtility
3128
/// <returns>Whether or not it is a mailto URI</returns>
3229
internal static bool IsMailtoUri(Uri mailtoUri)
3330
{
34-
if (mailtoUri != null)
35-
{
36-
return SecurityHelper.AreStringTypesEqual(
37-
mailtoUri.Scheme,
38-
Uri.UriSchemeMailto);
39-
}
40-
41-
return false;
31+
return mailtoUri is not null && string.Equals(mailtoUri.Scheme, Uri.UriSchemeMailto, StringComparison.OrdinalIgnoreCase);
4232
}
4333

4434
/// <summary>

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,6 @@ System.Windows.MessageBoxImage image
220220
}
221221
#endif
222222

223-
#if PRESENTATION_CORE || PRESENTATIONFRAMEWORK || WINDOWS_BASE
224-
225-
internal static bool AreStringTypesEqual(string m1, string m2)
226-
{
227-
return (string.Equals(m1, m2, StringComparison.OrdinalIgnoreCase));
228-
}
229-
230-
#endif //PRESENTATION_CORE || PRESENTATIONFRAMEWORK || WINDOWS_BASE
231-
232-
233223
#if WINDOWS_BASE
234224
///
235225
/// Read and return a registry value.

src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/BindUriHelper.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616
using MS.Win32;
1717
#endif
1818

19-
using System.Security;
2019
// The functionality in this class is shared across framework and core. The functionality in core
2120
// is a subset of the functionality in framework, so rather than create a dependency from core to
2221
// framework we have choses to duplicate this chunk of code.
2322
#if PRESENTATION_CORE
2423
namespace MS.Internal.PresentationCore
2524
#elif PRESENTATIONFRAMEWORK
26-
using MS.Internal.PresentationFramework; // SecurityHelper
25+
using MS.Internal.PresentationFramework;
2726

2827
namespace MS.Internal.Utility
2928
#elif PBTCOMPILER
30-
using MS.Internal.PresentationBuildTasks // SecurityHelper
29+
using MS.Internal.PresentationBuildTasks
3130

3231
namespace MS.Internal.Utility
3332
#elif REACHFRAMEWORK
34-
using MS.Internal.ReachFramework; // SecurityHelper
33+
using MS.Internal.ReachFramework;
3534

3635
namespace MS.Internal.Utility
3736
#else
@@ -88,7 +87,7 @@ static internal Uri BaseUri
8887
static internal bool DoSchemeAndHostMatch(Uri first, Uri second)
8988
{
9089
// Check that both the scheme and the host match.
91-
return (SecurityHelper.AreStringTypesEqual(first.Scheme, second.Scheme) && first.Host.Equals(second.Host) == true);
90+
return string.Equals(first.Scheme, second.Scheme, StringComparison.OrdinalIgnoreCase) && string.Equals(first.Host, second.Host);
9291
}
9392

9493
static internal Uri GetResolvedUri(Uri baseUri, Uri orgUri)
@@ -103,7 +102,7 @@ static internal Uri GetResolvedUri(Uri baseUri, Uri orgUri)
103102
{
104103
// if the orgUri is an absolute Uri, don't need to resolve it again.
105104

106-
Uri baseuri = (baseUri == null) ? BindUriHelper.BaseUri : baseUri;
105+
Uri baseuri = baseUri ?? BindUriHelper.BaseUri;
107106

108107
#if CF_Envelope_Activation_Enabled
109108
bool isContainer = false ;
@@ -166,7 +165,7 @@ internal static string GetReferer(Uri destinationUri)
166165
if (sourceZone == targetZone)
167166
{
168167
// We don't send any referer when going cross-scheme
169-
if (SecurityHelper.AreStringTypesEqual(sourceUri.Scheme, destinationUri.Scheme))
168+
if (string.Equals(sourceUri.Scheme, destinationUri.Scheme, StringComparison.OrdinalIgnoreCase))
170169
{
171170
// HTTPHeader requires the referer uri to be escaped.
172171
referer = sourceUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped);

0 commit comments

Comments
 (0)