{"record":{"id":"635aa26a2d8c8d6a","repo":"mgth/LittleBigMouse","slug":"enter-a-platform-action-name-containing-only-letters-digits","errorCode":null,"errorMessage":"Enter a platform action name containing only letters, digits, '_' or '-'.","messagePattern":"Enter a platform action name containing only letters, digits, '_' or '-'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs","lineNumber":205,"sourceCode":"        catch (JsonException)\n        {\n            return false;\n        }\n    }\n\n    public static string VolumePayload(int volume)\n    {\n        if (volume is < 0 or > 100)\n            throw new ArgumentOutOfRangeException(nameof(volume), \"Enter a volume between 0 and 100.\");\n        return volume.ToString(CultureInfo.InvariantCulture);\n    }\n\n    public static string PlatformActionName(string action)\n    {\n        var normalized = action.Trim();\n        if (normalized.Length is 0 or > 64\n            || normalized.Any(c => !char.IsAsciiLetterOrDigit(c) && c is not '_' and not '-'))\n            throw new ArgumentException(\n                \"Enter a platform action name containing only letters, digits, '_' or '-'.\",\n                nameof(action));\n        return normalized;\n    }\n\n    public static string ExperimentalLevelPayload(int value)\n    {\n        if (value is < 0 or > 10)\n            throw new ArgumentOutOfRangeException(nameof(value), \"Enter a test level between 0 and 10.\");\n        return value.ToString(CultureInfo.InvariantCulture);\n    }\n\n    public static bool TryParseVolume(string topic, string payload, out int volume)\n    {\n        volume = 0;\n        if (!topic.EndsWith(\"/platform_service/actions/volumechange\", StringComparison.OrdinalIgnoreCase))\n            return false;\n        try","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs#L187-L223","documentation":"PlatformActionName validates a Hisense VIDAA platform action name before it is used in an MQTT topic/payload. The name must be non-empty, at most 64 characters, and contain only ASCII letters, digits, '_' or '-'. Any other character (spaces, dots, slashes, non-ASCII) makes the library throw ArgumentException to prevent malformed platform action identifiers from being sent to the device.","triggerScenarios":"Calling HisenseVidaaProtocol.PlatformActionName with: an empty or whitespace-only string; a string longer than 64 chars after Trim(); or any string containing characters outside [A-Za-z0-9_-] (e.g. 'Volume Up', 'vol.up', 'ação').","commonSituations":"Hardcoding action names with spaces or dots copied from documentation; building action names dynamically from user input or UI labels that were never sanitized; localizing names so accented characters sneak in; concatenating prefixes that exceed 64 characters.","solutions":["Remove or replace disallowed characters (spaces, dots, slashes) with '_' or '-' before calling PlatformActionName.","Trim and cap the name at 64 characters.","Restrict action names to ASCII letters, digits, '_' and '-' at the point where users enter or select them.","Wrap the call in try/catch on ArgumentException to surface a friendly validation message in the UI."],"exampleFix":"// before\nvar name = PlatformActionName(userInput); // throws for 'Volume Up'\n// after\nvar cleaned = new string(userInput.Trim().Select(c => char.IsAsciiLetterOrDigit(c) ? c : (c == ' ' ? '_' : '-')).ToArray()).Take(64).ToArray();\nvar name = PlatformActionName(new string(cleaned));","handlingStrategy":"validation","validationCode":"public static bool IsValidPlatformActionName(string? action) =>\n    action is not null &&\n    action.Trim() is { Length: > 0 } n && n.Length <= 64 &&\n    n.All(c => char.IsAsciiLetterOrDigit(c) || c is '_' or '-');","typeGuard":"public static bool IsSafeActionName(string? s) => !string.IsNullOrWhiteSpace(s) && s.Trim().Length <= 64 && s.All(c => char.IsAsciiLetterOrDigit(c) || c == '_' || c == '-');","tryCatchPattern":"try { var name = HisenseVidaaProtocol.PlatformActionName(input); }\ncatch (ArgumentException ex) { ShowValidationError(ex.Message); }","preventionTips":["Sanitize action names at input time, replacing disallowed characters with '_' or '-'.","Keep a shared validation regex ([A-Za-z0-9_-]{1,64}) used both in the UI and before API calls.","Never build action names from free-form labels or localized strings."],"tags":["argument-validation","format-validation","mqtt","hisense"],"backgroundTag":"invalid-argument-format","analyzedSha":"7a42f01d47d99d223b8ee33ba4019af82adf1c48","analyzedAt":"2026-09-16T00:35:00.514Z","contentChangedAt":"2026-09-16T00:35:00.514Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}