fix(dcl): ASCII-only connection actor names, guarded ActorOf, and gate rejection of colliding connection names (review 2026-10-21 lane A M2)
ConnectionActorNames.Sanitize (shared by the DCL manager and the site deploy gate) keeps ASCII letters/digits and -_.*+:@&=,!~';() only. The manager fails a connection whose sanitised name is invalid or already used (Error + site event) instead of restarting; DeployCompileValidator rejects a config whose connection names collide after sanitising.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Actors;
|
||||
|
||||
/// <summary>
|
||||
/// Maps a data connection name to the Akka actor name of its <see cref="DataConnectionActor"/>
|
||||
/// (review 2026-10-21, lane A M2). Shared by <see cref="DataConnectionManagerActor"/> (which
|
||||
/// creates the actor) and the site deploy gate (which rejects a config whose connection names
|
||||
/// would collide once sanitised), so both always agree on the name.
|
||||
///
|
||||
/// <para>
|
||||
/// Every output is a legal Akka path element: ASCII letters and digits plus
|
||||
/// <c>-_.*+:@&=,!~';()</c> are kept, everything else — spaces, <c>/</c>, <c>#</c>, <c>$</c>
|
||||
/// and every non-ASCII character — becomes <c>-</c>. The previous sanitiser kept
|
||||
/// <see cref="char.IsLetterOrDigit(char)"/> (true for non-ASCII letters, which Akka refuses) and
|
||||
/// <c>$</c> (refused as a leading character), so "Ofen Süd" or "$PLC" threw out of
|
||||
/// <c>Context.ActorOf</c>. The mapping is NOT injective ("PLC A" and "PLC-A" both give
|
||||
/// "PLC-A"); callers must treat a collision as an error for the later connection.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class ConnectionActorNames
|
||||
{
|
||||
private const string KeptSymbols = "-_.*+:@&=,!~';()";
|
||||
|
||||
/// <summary>The actor name used for <paramref name="connectionName"/>.</summary>
|
||||
/// <param name="connectionName">The data connection's configured name.</param>
|
||||
/// <returns>A legal, non-empty Akka actor name.</returns>
|
||||
public static string Sanitize(string connectionName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(connectionName))
|
||||
return "-";
|
||||
|
||||
var chars = new char[connectionName.Length];
|
||||
for (var i = 0; i < chars.Length; i++)
|
||||
{
|
||||
var c = connectionName[i];
|
||||
chars[i] = (c is >= 'a' and <= 'z' or >= 'A' and <= 'Z' or >= '0' and <= '9') ||
|
||||
KeptSymbols.Contains(c)
|
||||
? c
|
||||
: '-';
|
||||
}
|
||||
|
||||
return new string(chars);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user