fix(serialization): Remove legacy BinaryFormatter support
SonarQube Analysis / sonarqube (pull_request) Successful in 4m42s
SonarQube Analysis / sonarqube (pull_request) Successful in 4m42s
The `[Serializable]` attribute and corresponding `[OnDeserialized]` methods have been removed from various breakdown classes. This eliminates reliance on `BinaryFormatter`, which is a deprecated and insecure serialization mechanism in modern .NET. This change also resolves SonarQube rule S5766 warnings by removing the context in which they apply, leading to cleaner and more secure code.
This commit is contained in:
@@ -8,7 +8,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
||||
/// <summary>
|
||||
/// Represents a DELETE SQL statement breakdown with FROM and WHERE clauses for SQL Server.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DeleteBreakdown : SqlBreakdownBase
|
||||
{
|
||||
protected readonly StatementParser Parser;
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
||||
/// <summary>
|
||||
/// Represents an INSERT SQL statement breakdown with column and value clauses for SQL Server.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class InsertBreakdown : SqlBreakdownBase
|
||||
{
|
||||
protected readonly StatementParser Parser;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||
@@ -10,7 +9,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
||||
/// <summary>
|
||||
/// Represents a SQL Server stored procedure call breakdown with procedure name and parameters.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ProcedureBreakdown : SqlBreakdownBase
|
||||
{
|
||||
protected readonly StatementParser Parser;
|
||||
@@ -46,20 +44,6 @@ public class ProcedureBreakdown : SqlBreakdownBase
|
||||
Parameters = parameters ?? new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
||||
/// constructors that normally initialize the procedure name and parameter collection
|
||||
/// (SonarQube rule S5766).
|
||||
/// </summary>
|
||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
||||
[OnDeserialized]
|
||||
private void OnDeserialized(StreamingContext context)
|
||||
{
|
||||
RevalidateBreakdownState();
|
||||
ProcedureName ??= new SqlClause();
|
||||
Parameters ??= new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the stored procedure name.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||
@@ -14,7 +13,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
||||
/// <summary>
|
||||
/// Represents a SELECT query breakdown with all clauses (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY).
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
#pragma warning disable S2325 // Methods and properties that don't access instance data should be static - False positive: These members access instance fields
|
||||
public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
||||
{
|
||||
@@ -108,28 +106,6 @@ public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
||||
/// constructors that normally initialize the parameter, WITH-clause, and clause backing
|
||||
/// fields (SonarQube rule S5766).
|
||||
/// </summary>
|
||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
||||
[OnDeserialized]
|
||||
private void OnDeserialized(StreamingContext context)
|
||||
{
|
||||
RevalidateBreakdownState();
|
||||
|
||||
_parameterList ??= new List<IQueryParam>();
|
||||
_withClauses ??= new List<IWithClause>();
|
||||
_selectClause ??= new SqlExpressionClause(splitOnComma: true);
|
||||
_fromClause ??= new SqlClause();
|
||||
_whereClause ??= new SqlExpressionClause(splitOnComma: false);
|
||||
_groupByClause ??= new SqlExpressionClause(splitOnComma: true);
|
||||
_havingClause ??= new SqlExpressionClause(splitOnComma: false);
|
||||
_orderByClause ??= new SqlExpressionClause(splitOnComma: true);
|
||||
_clausesCacheDirty = true;
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
||||
@@ -12,7 +11,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
||||
/// This class extends SqlBreakdownCollection with SQL Server-specific functionality,
|
||||
/// including support for T-SQL features like batches (GO), temporary tables, stored procedures, and CTEs.
|
||||
/// </remarks>
|
||||
[Serializable]
|
||||
public class QueryBreakdownCollection : SqlBreakdownCollection
|
||||
{
|
||||
private readonly List<QueryBreakdown> _queryBreakdowns;
|
||||
@@ -34,20 +32,6 @@ public class QueryBreakdownCollection : SqlBreakdownCollection
|
||||
_queryBreakdowns = new List<QueryBreakdown>(queryBreakdowns ?? Enumerable.Empty<QueryBreakdown>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates that the backing list survived deserialization, since deserialization bypasses
|
||||
/// the constructors that normally initialize it (SonarQube rule S5766).
|
||||
/// </summary>
|
||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
||||
[OnDeserialized]
|
||||
private void OnDeserialized(StreamingContext context)
|
||||
{
|
||||
if (_queryBreakdowns is null)
|
||||
{
|
||||
throw new SerializationException("Deserialized QueryBreakdownCollection is missing its backing list.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of QueryBreakdown objects.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
||||
/// <summary>
|
||||
/// Represents an UPDATE SQL statement breakdown with SET, FROM, and WHERE clauses for SQL Server.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class UpdateBreakdown : SqlBreakdownBase
|
||||
{
|
||||
protected readonly StatementParser Parser;
|
||||
|
||||
Reference in New Issue
Block a user