Class CollationNameValidator

Namespace: redb.Core.Query
Assembly: redb.Core.dll

Single source of truth for what may appear as a collation name in generated SQL.

This matters more than a normal setting. COLLATE takes an identifier, not a
value, so the name cannot be sent as a bound parameter: it is concatenated into the SQL text
the provider builds. An unchecked name is therefore a direct injection point, reachable from
application configuration.


Two independent defences, because either one alone is a single point of failure:
this validator rejects anything outside a conservative shape at the moment the value is
assigned, long before any SQL exists; and the emitters additionally quote the name
( in C#, quote_ident() in the in-database functions). A name that
somehow passed the first would still be inert after the second.


The accepted shape is deliberately narrower than what PostgreSQL allows. Real collation names
are things like und-x-icu, ru-x-icu, en_US.utf8, C; none of them
need quotes, spaces or punctuation beyond the four characters below. Widening this later is
safe, narrowing it is not.

public static class CollationNameValidator

Inheritance

Object→CollationNameValidator

Methods

IsValid(string?)

True when name would pass .

public static bool IsValid(string? name)

Quote(string)

Renders the name as a quoted SQL identifier. The double quote is doubled even though

public static string Quote(string name)

Validate(string)

Throws unless name is a plausible

public static void Validate(string name)