{"record":{"id":"aa5ae3bb3bb3e3da","repo":"iOfficeAI/OfficeCLI","slug":"pivot-name-contains-invalid-control-characters","errorCode":null,"errorMessage":"pivot name contains invalid control characters","messagePattern":"pivot name contains invalid control characters","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.cs","lineNumber":186,"sourceCode":"    /// (that is the caller's responsibility).\n    /// R16-2: extracted from CreatePivotTable so SetPivotTableProperties can\n    /// reuse the same validation — previously Set accepted empty/whitespace\n    /// names without any check.\n    /// </summary>\n    private static string ValidatePivotName(string name)\n    {\n        // Empty string is rejected — a blank name is always an error.\n        if (string.IsNullOrEmpty(name))\n            throw new ArgumentException(\"pivot name must not be empty\");\n        var trimmed = name.Trim();\n        // Whitespace-only names are rejected — R8-4.\n        if (trimmed.Length == 0)\n            throw new ArgumentException(\"pivot name must not be whitespace-only\");\n        // ASCII control characters are rejected — R8-5.\n        foreach (var ch in trimmed)\n        {\n            if (ch < 0x20 || ch == 0x7F)\n                throw new ArgumentException(\"pivot name contains invalid control characters\");\n        }\n        // 255-character limit — R11-4.\n        if (trimmed.Length > 255)\n            throw new ArgumentException(\"pivot name exceeds 255-character limit\");\n        return trimmed;\n    }\n\n    /// <summary>\n    /// Canonical key set recognized by the pivot Add / Set pipeline. Any\n    /// property whose NORMALIZED key is not in this set is reported as\n    /// UNSUPPORTED (Add: stderr warning; Set: returned unsupported list).\n    /// Must stay in sync with the switch in SetPivotTableProperties and\n    /// every properties lookup in CreatePivotTable.\n    /// </summary>\n    private static readonly HashSet<string> _knownPivotKeys =\n        new(StringComparer.OrdinalIgnoreCase)\n        {\n            \"source\", \"src\", \"name\", \"position\", \"pos\", \"style\",","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.cs#L168-L204","documentation":"Thrown by ValidatePivotName when the trimmed name contains any ASCII control character (code point < 0x20, or 0x7F DEL). These characters are invalid in OOXML display names and would corrupt the XML or render as garbage in Excel's pivot table name field. This is R8-5.","triggerScenarios":"Calling Add/Set pivot name with embedded control characters such as tab (\\t), newline (\\n), carriage return (\\r), or DEL. These can sneak in from copy-paste, unescaped user input, or binary data interpreted as a string.","commonSituations":"Name pasted from a source that includes hidden control characters; newline injected via a multi-line input field; binary/encoding issue producing control bytes; tab characters from spreadsheet cell references.","solutions":["Strip or replace control characters from the name before passing it.","Sanitize user input by removing characters below 0x20 and 0x7F.","Use plain ASCII or Unicode printable text for pivot names."],"exampleFix":"// before — contains a tab character\nSet pivot name='Sales\\tPivot'\n// after\nSet pivot name='Sales Pivot'","handlingStrategy":"validation","validationCode":"if (pivotName.Any(ch => ch < 0x20 || ch == 0x7F))\n    throw new ArgumentException(\"Pivot name contains invalid control characters.\");","typeGuard":"static bool HasNoControlChars(string name) =>\n    name.All(ch => ch >= 0x20 && ch != 0x7F);","tryCatchPattern":null,"preventionTips":["Sanitize user input by removing characters below 0x20 and 0x7F before using as a name.","Be cautious with copy-pasted text that may contain hidden control characters.","Use printable ASCII or Unicode text for pivot names."],"tags":["pivot","excel","naming","validation","control-characters","sanitization"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}