Skip to content

Commit

Permalink
refactor: Run code through dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
hangy committed Mar 2, 2025
1 parent d6860e6 commit 570ef2e
Show file tree
Hide file tree
Showing 64 changed files with 2,119 additions and 2,063 deletions.
2 changes: 1 addition & 1 deletion Microsoft.Security.Application.Encoder/AntiXSS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,4 @@ public static string VisualBasicScriptEncode(string input)
return Encoder.VisualBasicScriptEncode(input);
}
}
}
}
2 changes: 1 addition & 1 deletion Microsoft.Security.Application.Encoder/UrlEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static class UrlEncoder
/// <summary>
/// The values to output for each character.
/// </summary>
private static char[][] characterValues;
private static required char[][]? characterValues;

/// <summary>
/// Encodes according to the URL Path encoding rules, RFC 1738.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,4 +1066,4 @@ public void GetSafeHtmlFragment_OutOfOrderTagsShouldStillRemoveScriptsTwo()
Assert.AreEqual(expected, actual);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static IApplicationServices Provider
/// <returns>A <see cref="CtsConfigurationSetting"/> for the sepecified setting from the specified sub section.</returns>
public static CtsConfigurationSetting GetSimpleConfigurationSetting(string subSectionName, string settingName)
{
CtsConfigurationSetting result = null;
CtsConfigurationSetting? result = null;
IList<CtsConfigurationSetting> settings = Provider.GetConfiguration(subSectionName);

foreach (CtsConfigurationSetting setting in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override int MaxCharCount
/// <returns>
/// The encoded character.
/// </returns>
public static string GetCharacterFallback(char charUnknown)
public static string? GetCharacterFallback(char charUnknown)
{
if (charUnknown <= 0x153 &&
charUnknown >= 0x82)
Expand Down Expand Up @@ -255,7 +255,7 @@ private sealed class AsciiFallbackBuffer : EncoderFallbackBuffer
/// <summary>
/// The fallback string.
/// </summary>
private string fallbackString;
private required string fallbackString;

Check failure on line 258 in Microsoft.Security.Application.HtmlSanitization/Globalization/AsciiEncoderFallback.cs

View workflow job for this annotation

GitHub Actions / build

Required member 'AsciiEncoderFallback.AsciiFallbackBuffer.fallbackString' cannot be less visible or have a setter less visible than the containing type 'AsciiEncoderFallback.AsciiFallbackBuffer'.

/// <summary>
/// Gets the maximum character count for the buffer.
Expand Down Expand Up @@ -373,4 +373,4 @@ public override void Reset()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public bool IsWindowsCharset
/// <summary>
/// Gets or sets the description for the character set.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification="Using default get/set syntax.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Using default get/set syntax.")]
public string Description
{
get;
Expand Down Expand Up @@ -353,4 +353,4 @@ public bool TryGetEncoding(out Encoding? attemptedEncoding)
return discoveredEncoding;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,25 @@ public CharsetNotInstalledException(int codePage, string message) :
base(codePage, message)
{
}

/// <summary>
/// The exception that is thrown when an attempt is made to use a character set that is not installed on the system.
/// </summary>
/// <param name="codePage">The code page number of the character set that is not installed.</param>
public CharsetNotInstalledException(int codePage) : base(codePage)
{
}

public CharsetNotInstalledException(string message) : base(message)
{
}

public CharsetNotInstalledException(string message, Exception innerException) : base(message, innerException)
{
}

public CharsetNotInstalledException() : base()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class CodePageMap : CodePageMapData
/// <summary>
/// The ranges for the current codepage.
/// </summary>
private CodePageRange[] ranges;
private required CodePageRange[] ranges;

/// <summary>
/// The previous index used for range operations.
Expand Down Expand Up @@ -131,7 +131,7 @@ public bool IsUnsafeExtendedCharacter(char ch)
{
int i = this.lastRangeIndex;

while (++ i < this.ranges.Length)
while (++i < this.ranges.Length)
{
if (ch > this.ranges[i].Last)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal enum CodePageFlags : byte
/// <summary>
/// Contains the data and functions necessary to map a code page.
/// </summary>
internal class CodePageMapData
internal static class CodePageMapData
{
/// <summary>
/// An array holding all the known codepages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal class Culture
/// <summary>
/// The culture info.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification="Set in CultureCharsetDatabase.cs.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Set in CultureCharsetDatabase.cs.")]
private CultureInfo cultureInfo;

/// <summary>
Expand Down Expand Up @@ -105,7 +105,7 @@ public string Description
/// <summary>
/// Gets or sets the native description.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification="Using default get/set syntax.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Using default get/set syntax.")]
public string NativeDescription
{
get;
Expand Down Expand Up @@ -164,4 +164,4 @@ internal void SetCodepageDetectionPriorityOrder(int[] newCodepageDetectionPriori
this.codepageDetectionPriorityOrder = newCodepageDetectionPriorityOrder;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ private static GlobalizationData LoadGlobalizationData(string defaultCultureName

var newData = new GlobalizationData();

Culture invariantCulture = null;
Culture? invariantCulture = null;
Culture culture;
Charset charset;

Expand Down Expand Up @@ -1289,13 +1289,13 @@ private static GlobalizationData LoadGlobalizationData(string defaultCultureName
*/
IList<CtsConfigurationSetting> settings = ApplicationServices.Provider.GetConfiguration("Globalization");

string charSetArg = null;
string aliasNameArg = null;
string defaultNameArg = null;
string cultureArg = null;
string windowsCharsetArg = null;
string mimeCharsetArg = null;
string webCharsetArg = null;
string? charSetArg = null;
string? aliasNameArg = null;
string? defaultNameArg = null;
string? cultureArg = null;
string? windowsCharsetArg = null;
string? mimeCharsetArg = null;
string? webCharsetArg = null;
int codePage;
int lcid;
Charset charset1;
Expand Down Expand Up @@ -2347,7 +2347,7 @@ internal class GlobalizationData
/// <summary>
/// Gets or sets the default culture.
/// </summary>
public Culture DefaultCulture
public required Culture DefaultCulture
{
get;
set;
Expand All @@ -2357,7 +2357,7 @@ public Culture DefaultCulture
/// Gets or sets the unicode charset.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Uses default get/set syntax.")]
public Charset UnicodeCharset
public required Charset UnicodeCharset
{
get;
set;
Expand All @@ -2367,7 +2367,7 @@ public Charset UnicodeCharset
/// Gets or sets the utf 8 charset.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Uses default get/set syntax.")]
public Charset Utf8Charset
public required Charset Utf8Charset
{
get;
set;
Expand All @@ -2376,7 +2376,7 @@ public Charset Utf8Charset
/// <summary>
/// Gets or sets the default detection priority order.
/// </summary>
public int[] DefaultDetectionPriorityOrder
public required int[] DefaultDetectionPriorityOrder
{
get;
set;
Expand Down Expand Up @@ -2445,7 +2445,7 @@ internal int MaxCharsetNameLength
/// <summary>
/// Gets or sets the name to culture map.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification="Uses dictionary syntax to set value. FXCop misses this.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Uses dictionary syntax to set value. FXCop misses this.")]
internal Dictionary<string, Culture> NameToCulture
{
get
Expand All @@ -2462,8 +2462,8 @@ internal Dictionary<string, Culture> NameToCulture
/// <summary>
/// Gets or sets the ascii charset.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification="Uses default get/set syntax.")]
internal Charset AsciiCharset
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Uses default get/set syntax.")]
internal required Charset AsciiCharset
{
get;
set;
Expand Down Expand Up @@ -2501,4 +2501,4 @@ public int GetHashCode(int obj)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,26 @@ protected InvalidCharsetException(SerializationInfo info, StreamingContext conte
base(info, context)
{
}

/// <summary>
/// Represents the exception that is thrown when an invalid charset is encountered during HTML sanitization.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public InvalidCharsetException(string message) : base(message)
{
}

/// <summary>
/// Represents an exception that is thrown when an invalid character set is encountered during HTML sanitization.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public InvalidCharsetException(string message, Exception innerException) : base(message, innerException)
{
}

public InvalidCharsetException() : base()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,4 @@ public override object Clone()
return newEncoding;
}
}
}
}
32 changes: 16 additions & 16 deletions Microsoft.Security.Application.HtmlSanitization/Sanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public static void GetSafeHtml(TextReader sourceReader, TextWriter destinationWr
{
HtmlToHtml htmlObject = new()
{
FilterHtml = true,
OutputHtmlFragment = false,
NormalizeHtml = true
};
FilterHtml = true,
OutputHtmlFragment = false,
NormalizeHtml = true
};

htmlObject.Convert(sourceReader, destinationWriter);
}
Expand All @@ -154,10 +154,10 @@ public static void GetSafeHtml(TextReader sourceReader, Stream destinationStream
{
HtmlToHtml htmlObject = new()
{
FilterHtml = true,
OutputHtmlFragment = false,
NormalizeHtml = true
};
FilterHtml = true,
OutputHtmlFragment = false,
NormalizeHtml = true
};

htmlObject.Convert(sourceReader, destinationStream);
}
Expand All @@ -177,10 +177,10 @@ public static void GetSafeHtmlFragment(TextReader sourceReader, TextWriter desti
{
HtmlToHtml htmlObject = new()
{
FilterHtml = true,
OutputHtmlFragment = true,
NormalizeHtml = true
};
FilterHtml = true,
OutputHtmlFragment = true,
NormalizeHtml = true
};

htmlObject.Convert(sourceReader, destinationWriter);
}
Expand All @@ -200,10 +200,10 @@ public static void GetSafeHtmlFragment(TextReader sourceReader, Stream destinati
{
HtmlToHtml htmlObject = new()
{
FilterHtml = true,
OutputHtmlFragment = true,
NormalizeHtml = true
};
FilterHtml = true,
OutputHtmlFragment = true,
NormalizeHtml = true
};

htmlObject.Convert(sourceReader, destinationStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public string Value
private set;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class CtsConfigurationSection : ConfigurationSection
/// <summary>
/// The configuration properties.
/// </summary>
private static ConfigurationPropertyCollection properties;
private static required ConfigurationPropertyCollection? properties;

Check failure on line 38 in Microsoft.Security.Application.HtmlSanitization/Shared/CtsConfigurationSection.cs

View workflow job for this annotation

GitHub Actions / build

The modifier 'required' is not valid for this item

/// <summary>
/// Gets a dictionary for the subsections in the configuration file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ internal void AddArgument(string name, string value)
this.arguments.Add(new CtsConfigurationArgument(name, value));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ protected ExchangeDataException(SerializationInfo info, StreamingContext context
base(info, context)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ExchangeDataException"/> class.
/// </summary>
public ExchangeDataException() : base()
{
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class DefaultApplicationServices : IApplicationServices
/// <summary>
/// The configuration sub sections from the CTS application settings.
/// </summary>
private volatile Dictionary<string, IList<CtsConfigurationSetting>> configurationSubSections;
private volatile required Dictionary<string, IList<CtsConfigurationSetting>> configurationSubSections;

Check failure on line 44 in Microsoft.Security.Application.HtmlSanitization/Shared/DefaultApplicationServices.cs

View workflow job for this annotation

GitHub Actions / build

Required member 'DefaultApplicationServices.configurationSubSections' cannot be less visible or have a setter less visible than the containing type 'DefaultApplicationServices'.

/// <summary>
/// Gets the configuration subsection specified.
Expand All @@ -62,7 +62,7 @@ public IList<CtsConfigurationSetting> GetConfiguration(string subSectionName)
{
try
{
CtsConfigurationSection section = ConfigurationManager.GetSection("CTS") as CtsConfigurationSection;
CtsConfigurationSection? section = ConfigurationManager.GetSection("CTS") as CtsConfigurationSection;

if (section != null)
{
Expand Down
Loading

0 comments on commit 570ef2e

Please sign in to comment.