Skip to content

Sanitized Struct

A type that sanitizes a given string by removing control characters and escaping special characters to prevent log injection attacks.

C#
public readonly record struct Sanitized : System.IEquatable<Abblix.Utils.Sanitized>

Implements System.IEquatable<Sanitized>

Properties

Sanitized.Source Property

The original, untrusted value. Sanitization is applied lazily inside ToString(); reading this property directly bypasses sanitization and exposes raw input.

C#
public object? Source { get; init; }

Property Value

System.Object

Methods

Sanitized.ToString() Method

Returns the sanitized string representation of the source string.

C#
public override string ToString();

Returns

System.String
A sanitized string with control characters removed and special characters escaped.

Sanitized.Value(object) Method

Creates a new Sanitized instance with the specified source object.

C#
public static Abblix.Utils.Sanitized Value(object? source);

Parameters

source System.Object

The source object to be sanitized when converted to string.

Returns

Sanitized
A new Sanitized instance.

Operators

Sanitized.implicit operator Sanitized(string) Operator

Wraps a raw string in a Sanitized value so the stripping pass runs once at formatting time.

C#
public static Abblix.Utils.Sanitized implicit operator Abblix.Utils.Sanitized(string? source);

Parameters

source System.String

The raw string to sanitize; may be null.

Returns

Sanitized

Sanitized.implicit operator Sanitized(Uri) Operator

Wraps a System.Uri in a Sanitized value so the stripping pass runs once at formatting time. The URI is converted to its string form before sanitization.

C#
public static Abblix.Utils.Sanitized implicit operator Abblix.Utils.Sanitized(System.Uri? source);

Parameters

source System.Uri

The URI to sanitize; may be null.

Returns

Sanitized